2

Is the C preprocessor for Mac OSX not working with Mojave correctly, or am I making some dumb mistake? The code below compiles but will not print "test" to the console.

According to https://sourceforge.net/p/predef/wiki/OperatingSystems/ and multiple Stack Overflow posts I have looked at __APPLE__ should do the trick. I've also tried __MACH__ and using __APPLE__ && __MACH__ but this does not work either.

I'm compiling in terminal via gcc.

Is it possible that these don't work with the newest version of OSX as it was only released a few weeks ago? I never had this problem until I updated to Mojave.

I've also tried calling a function in place of printf("test"); but the results are the same.

#include <stdio.h>
int main()
{  
    #ifdef __APPLE__
      printf("test");
    #endif

    return 0;
}
runesbane
  • 75
  • 7
  • You're using only a single underscore. Does \_\_APPLE\_\_ or \_\_MACH\_\_ work? – CoffeeTableEspresso Oct 16 '18 at 23:59
  • No, sorry, In my real code I'm using the double underscore, just a typo in here. I'll edit the post. – runesbane Oct 17 '18 at 00:00
  • Can you post the output of `gcc -dM -E - < /dev/null` ? see [gcc-dump-preprocesor-defines](https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines). – KamilCuk Oct 17 '18 at 00:04
  • `#define __APPLE__ 1` is missing from it, so that's clearly why it isn't working. I am going to reinstall gcc and see if it comes back. – runesbane Oct 17 '18 at 00:10
  • reinstalling fixed this. May have corrupted from OS update, I had to reinstall xCode command line tools when i first upgraded too. – runesbane Oct 17 '18 at 00:33

1 Answers1

0

Reinstalling GCC seems to have resolved the issue. #define __APPLE__ 1 was missing from gcc when I ran gcc -dM -E - < /dev/null in terminal. It has returned upon reinstall. Possible corruption from upgrading.

runesbane
  • 75
  • 7