Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > pascal keyword in typedefs - compile error?

pascal keyword in typedefs - compile error?
Thread Tools
Forum Regular
Join Date: Dec 2004
Status: Offline
Reply With Quote
Oct 1, 2005, 01:28 PM
 
Hi all,

I'm working at understand someone else's ancient Carbon code and have come across something I'm not quite sure how to address.

When utilizing the 'pascal' keyword in typedefs, Xcode gives me errors. For example:

typedef pascal FOO (SomeObject pObject);

Xcode says "Parse error before FOO" and if I remove the pascal keyword, everything builds... but I get an Illegal Instruction the very first time any of these 'pascal' typedefs are used. Granted it could be from another reason, but my first thought is that if they put 'pascal' there, it was for good reason.

I'm thinking this keyword for typedefs is some sort of compiler option? I can't even find examples of this on the web.

Rob
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 1, 2005, 02:30 PM
 
The "pascal" keyword isn't an actual type so much as a modifier, I think. It specifies how the stack should be handled for the function. Probably when the code was written, the compiler would infer a default type, but now it needs the type to be explicit. That's my guess.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
rslifka  (op)
Forum Regular
Join Date: Dec 2004
Status: Offline
Reply With Quote
Oct 1, 2005, 02:40 PM
 
I came across this on /.

However, C and C++ compilers for the Mac all accept the "pascal" keyword, which is included in all the header files for the API. Besides that, you can ignore it, except in the special case where you need to pass a pointer to the API for a callback function. Then you need to declare your function as pascal, too. You have never had to declare all your functions pascal.
This is precisely the special case I'm in. Callback function pointers. Xcode/GCC/whatever is rejecting use of this 'pascal' keyword in creating the typedefs for the function pointers but it allows the use in function declarations.

Rob
     
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Oct 1, 2005, 06:39 PM
 
I'm fairly certain there are some build options regarding pascal, so you may want to look through those. Though they may only be pascal strings options.
     
Fresh-Faced Recruit
Join Date: Jan 2002
Status: Offline
Reply With Quote
Oct 2, 2005, 05:15 PM
 
The Pascal calling convention has been a no-op since the PowerPC was introduced, and is a left-over from 68K - the crash will be down to something else.

However, even though it's a no-op, CodeWarrior has always recognised the 'pascal' keyword as a type qualifier - so will complain if you pass a non-pascal callback to a function expecting a function pointer declared as pascal (as it should: the types are different, so you can't mix them without an explicit cast).

Unfortunately gcc doesn't recognise the 'pascal' keyword, so if you have code that declares callbacks with 'pascal' directly rather than using the compiler-aware macros from ConditionalMacros.h then it won't compile. The simplest approach is either to take it out, or to -Dpascal= when using gcc to have it ignored.

Xcode's only Pascal support is to recognise "\pfoo" sequences as Pascal strings (e.g., a Str255 - rather than a C-style NULL terminated string, the initial byte holds the length of the string and there may not be a trailing NULL).
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:38 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2