MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: MathLink String type

To match the code generated by mprep, you should declare any
string arguments to installable MathLink functions as "const char *",
not "char *".  So, change the line:

	int StringLength( char * s)
	int StringLength( const char * s)

and things should work.  This, of course, means that you can't make
any modifications to the string 's', which is well and good, as things
could start breaking if you tried to anyway.


John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

> I am not able to compile simple MathLink function (Mathematica v. 4, Linux),
> which use a string as an argument. Like this:
> :Begin:
> :Function:       StringLength
> :Pattern:        StringLength[s_String]
> :Arguments:      { s}
> :ArgumentTypes:  { String }
> :ReturnType:     Integer
> :End:
> :Evaluate: StringLength::usage = "StringLength[s_String] gives the
> length of s."
> #include "mathlink.h"
> int StringLength( char * s)
> { int i=0; char *t = s;
>   while(*(t++)) i++;
>   return i; }
> int main(argc, argv)int argc; char* argv[];
> { return MLMain(argc, argv); }
> The compiling stage aborts with
> conflicting types for `StringLength'
> previous declaration of `StringLength'
> The mcc compiler replaces the  char * s argument specification by
> int StringLength P(( kcharp_ct _tp1));
> Such declaration I do not understand well.
> Thank for the advice
> Sent via
> Share what you know. Learn what you don't.

  • Prev by Date: Re: Multiple Integrals
  • Next by Date: Re: Linear Algebra `MatrixManipulation`
  • Previous by thread: MathLink String type
  • Next by thread: Re: MathLink String type