MathGroup Archive 1999

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

Search the Archive

Re: MathLink String type

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20002] Re: [mg19993] MathLink String type
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Sat, 25 Sep 1999 02:40:36 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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)
to
	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.


Sincerely,

John Fultz
jfultz at wolfram.com
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
> StringLength.tm.c:37: conflicting types for `StringLength'
> StringLength.tm:14: 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 Deja.com http://www.deja.com/
> 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