[comp.sys.mac.hypercard] sprintf

dudek@ai.toronto.edu (Gregory Dudek) (02/17/88)

  Just to correct some apparent misinformation that has been propagated
on this subjec...

In article <5383@cit-vax.Caltech.Edu> palmer@tybalt.caltech.edu.UUCP (David Palmer) writes:
>In article <943@cadre.dsl.PITTSBURGH.EDU> cgw@cadre.dsl.pittsburgh.edu.UUCP (Gray Watson) writes:
>>>  sprintf(tempstring, "%s %f %s %f", "\pthe square of ", x, "is", (x *x));
>>>  DrawString(tempstring);

  [ etc, etc ]
>>
>
>The string produced by "\pthe square of " is NOT null terminated (it is
>a Pascal string, and so the length is specified by a byte at the beginning,
>...
>True, but the '\p' in "\pHello Dolly" is just a directive to tell the
>compiler to count the characters for itself, and the string is stored in
>memory as "\013Hello Dolly", with no null termination.
>

  Aztec C produces a C-string *WITH* a null terminator when it sees:
"\Pfoo".   In other words it's a legal Pascal string but has an EXTRA
character (null) that Pascal routines won't notice, thus making it a
legal C-string also.  This seems like a very sensible idea since C
routines invoked on it won't blow up & things like strcpy still work.
  I don't know what other complers do, but I would be seem reasonable if they
did the same.
  Of course, this doesn't solve the original poster's problem.  He should
use something like:
  sprintf(tmp,"%s %d ect",...);  DrawString(CtoPascal(tmp));
where CtoPascal is appropriately defined (most compilers include 
a library routine that does this).

  As for glue routines, Aztec C uses them only for *some* ROM traps; most
are defined as straight ROM entries.

  Greg Dudek
-- 
Dept. of Computer Science (vision group)    University of Toronto
Reasonable mailers:  dudek@ai.toronto.edu
Other UUCP: {uunet,ihnp4,decvax,linus,pyramid,
		dalcs,watmath,garfield,ubc-vision,calgary}!utai!dudek
ARPA: user%ai.toronto.edu@relay.cs.net