Strange (?) Syntax Error

Strange (?) Syntax Error

Post by hierophan » Wed, 02 Jun 2004 07:05:50

My CW IDE (Learning v3, IDE v5.0) chokes on a syntax error with
objective c/cocoa, but Xcode doesn't. Code snippet:

[[NSColor whiteColor] set]; // set drawing color to white
NSRectFill( [self bounds] ); // fill the view with white

// declare color vars
float red = 0.0;
float green = 0.0;
float blue = 0.0;

CW gives a expression syntax error on each variable definition above.
If, however, I move them to above the [[NSColor whiteColor] set]
call, no error is generated. AFAIK, there is nothing wrong with this
syntax, and Xcode doesn't think so either.

Anyone have any clues?

Strange (?) Syntax Error

Post by Dave Smit » Wed, 02 Jun 2004 07:54:19

In article < XXXX@XXXXX.COM >,

If you have ANSI Strict (I think or some other setting lice C99) turned
on, then you have to declare variables before you do any other code in a
block. So, if you move the "float..." stuff before the 2 lines of code,
it should be fine. Or you can find the setting mentioned above and turn
it off.



Strange (?) Syntax Error

Post by hierophan » Wed, 02 Jun 2004 14:31:38

This would seem to be the case ut the ANSI Strict setting is off, and
I have calls such as:
float height = [self bounds].size.height;
which is an accessor method, so the same rules (one would think) would
apply, but it doesn't seem to matter.

Strange (?) Syntax Error

Post by MW Ro » Wed, 02 Jun 2004 23:30:06

In article < XXXX@XXXXX.COM >,

This is the difference between C and C++ in the C89 standard. In C
you need to declare all variables first in a block before any code is
generated. You can turn on C99 extensions to allow this to compiled or
use .mm to force C++ compiling.

If XCode doesn't do this then it is compiling them as Objective C++ or
has the C99 extensions by default.


Metrowerks, one of the world top 100 companies and influencers
in the software development industry. - SD Times May 2004

Metrowerks, maker of CodeWarrior
Ron Liechty - XXXX@XXXXX.COM -