1

I'm porting an iPhone game to Mac and I'm writing a file with common defines that has the following:

// first reset all defines

#undef TARGET_IPHONE
#undef TARGET_MAC

// set defines

#if TARGET_OS_MAC
#if TARGET_OS_IPHONE
#define TARGET_IPHONE
#else
#define TARGET_MAC
#endif
#endif

#ifdef TARGET_IPHONE
#error err1
#endif

#ifndef TARGET_IPHONE
#error err2
#endif

But when building for iPhone, both err1 and err2 are thrown by the compiler.

I don't get it, what's the problem there?

EDIT: After about an hour of trying things with no luck, I had to add my own define to xcode build options.

1
  • 1
    Just a quick code readability hint: you can put whitespace between the # and the directive itself (i.e. # if...) and thus achieve a reasonable simulation of normal indentation. – mu is too short Mar 6 '11 at 21:34
1

Your code is fine. On my compiler (gcc mingw) #error err2 is thrown. And if i insert

#define TARGET_OS_MAC 1
#define TARGET_OS_IPHONE 1

where your // set defines is, #error err1 is thrown.

0

This looks like either a compiler bug, or you need special permission from Apple to use #ifndef (that's a joke (I think).)

You might try this equivalent syntax that might work with Apple's compiler:

#if !defined(TARGET_IPHONE)

or

#if !TARGET_IPHONE

or even

#ifdef TARGET_IPHONE

#else

This is worrisome, though - I'd look for an updated or different compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.