Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!ml27192 From: ml27192@uxa.cso.uiuc.edu (lanett mark) Newsgroups: comp.sys.mac.programmer Subject: Re: Str255 in C Message-ID: <1991Jan15.181224.4809@ux1.cso.uiuc.edu> Date: 15 Jan 91 18:12:24 GMT References: <47171@cci632.UUCP> <3756@uakari.primate.wisc.edu> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 27 bin@primate.wisc.edu (Brain in Neutral) writes: >From article <47171@cci632.UUCP>, by ph@cci632.UUCP (Pete Hoch): >> Giving benefit of the doubt, this reply suffers from less than precise >> wording. In reality the "\p" is only a place holder for the pascal >> style character count. I believe the compiler supplies this number >> so it is evaluated very early on. However this is still a c string! >> That means it is still NULL terminated. >Nope. Depends on the compiler, so check your manual first. Well for the case 'Str255 a = "\pThis will work"' the \p is replaced with the length count _and_ the string is still a null-terminated C string. So you can do a strcpy and it will work for both Think and MPW. However, if you just get a pascal string from the toolbox it will _not_ have the terminator and that _won't_ work (you must use strncpy with n=b[0] (+1?) ). C-created pascal strings are terminated; pascal-created pascal strings are not (or course). >And if you want your code to be portable, don't write code that >*depends* on the compiler's behavior. Yes. Mark Lanett