Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "\pPascal strings again"



On Nov 29, 2005, at 8:43 AM, alex wrote:

I've been using "/p" [sicfor about the same amount of time if not a wee bit longer :)  It wasn't supported on Windows and (I think) gcc until recently so that's why I was saying it was non-standard. 


That is correct.

The whole pascal string thing is a holdover (as you know) from the early Mac OS which was all in pascal conventions and then everyone wanted to use C... so what to do with all those interfaces with pascal strings that you wanted to call from C?  "\p" and our ever present friend the pascal C keyword.


The 'pascal' keyword actually became a no-op in the transition to PowerPC more than ten years ago.  It specified whether arguments should be pushed on the calling stack in left-to-right or right-to-left order.  Because PowerPC passes function arguments in registers,  'pascal' is meaningless in the PowerPC ABI.

It was my understanding that the "\p" character was the place holder for the length byte of the string


You could consider it that if you wish.

and also a compiler directive to insert the length there. 


That's its primary purpose.

Kinda like c-style strings that have a null byte magically inserted at the end,


Not so magically: that is the language definition.

or forming a pascal string using another sort of escape code (like octal and counting the length yourself). 


Ick.

Been there- done that on Windows... 


I've never tried to place the \p anywhere else in a string except for at the start but I imagine it would cause a compiler error (at least I hope). :)


No such luck:

Str255 theString = "My \pPascal String";

results in

"y pPascal String" (followed by garbage)

That is, the first (length) byte is 0x4d (ASCII "M") and the backslash-p escapes to a lowercase "p".  

So if you want to use Pascal string constants, the \p must be at the beginning of the string, or it is ignored and treated like a C string.

Chris
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: How to rename the volume name of a USB flash memory stick? (From: Laurence Harris <email@hidden>)
 >"\pPascal strings again" (From: alex <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.