Article View: comp.sys.mac
Article #25121Re: sprintf() bug?
From: Gregory Dudek
Date: Tue, 16 Feb 1988 22:28
Date: Tue, 16 Feb 1988 22:28
42 lines
2468 bytes
2468 bytes
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
Technical Details
Message-ID:
<1988Feb16.172826.1393@jarvis.csri.toronto.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!ai.toronto.edu!dudekReferences:
<4VzXREy00WABE7k0FU@andrew.cmu.edu> <5349@cit-vax.Caltech.Edu> <943@cadre.dsl.PITTSBURGH.EDU> <5383@cit-vax.Caltech.Edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.mac,comp.sys.mac.digest,comp.sys.mac.hypercard Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!ai.toronto.edu!dudek From: dudek@ai.toronto.edu (Gregory Dudek) Subject: Re: sprintf() bug? Message-ID: <1988Feb16.172826.1393@jarvis.csri.toronto.edu> Keywords: C,sprintf,strings Reply-To: dudek@ai.toronto.edu (Gregory Dudek) Organization: Department of Computer Science, University of Toronto References: <4VzXREy00WABE7k0FU@andrew.cmu.edu> <5349@cit-vax.Caltech.Edu> <943@cadre.dsl.PITTSBURGH.EDU> <5383@cit-vax.Caltech.Edu> Date: Tue, 16-Feb-88 17:28:25 EST