views:

420

answers:

2

I have tried this:

CGRectMake(0.0f, kFooBarHeight, 100.0f, 10.0f);

I get an error "unexpected ';' before ')'", and "too few arguments for CGRectMake". When I exchange this with:

CGFloat foo = kFooBarHeight;
CGRectMake(0.0f, foo, 100.0f, 10.0f);

then all is fine. Are constants not suitable to pass along as parameters?

+12  A: 

Without the kFooBarHeight definition it's impossible to give a good answer but I'm guessing you defined kFooBarHeight using a preprocessor definition? If so, best guess is you added a semicolon to the end. Your definition should look like this: #define kFooBarHeight 10 but you have set as: #define kFooBarHeight 10; .

If what you have is the second definition when it replaced by the preprocessor you get:

CGRectMake(0.0f, 10;, 100.0f, 10.0f);

That's why your second example works correctly, it expands to:

CGFloat foo = 10;;
CGRectMake(0.0f, foo, 100.0f, 10.0f);

Again, this is just an educated guess, it's impossible to say without the actual definition of kFooBarHeight.

Argothian
You're totally right, I had a semikolon there! Good guess ;)
Thanks
+3  A: 

Change your

#define kFooBarHeight 100;

to

#define kFooBarHeight 100

Semicolons should not be used to terminate #defines unless you know for certain how it will be used.

Dave Gamble