6

I wonder why on MacOSX the macro __unix__ is not defined.

Isn't MacOSX a BSD UNIX derivative?

If I define the __unix__ macro in my code, could I have some issues?

In general, when checking the current platform, I prefer to do something like:

#ifdef __unix__
...
#endif

instead of:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
...
#endif

Could the best option be to define my own macro in a single place? E.g.:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
#define UNIX_
#endif
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 1
    If you choose to do that, do not use double underscore in the name. – William Pursell Oct 27 '11 at 14:36
  • 1
    you'll get more eyes on your problem if you change one of your tags to 'c'. Good luck. – shellter Oct 27 '11 at 15:29
  • What sort of things would you surround with your `#ifdef __unix__` or `#ifdef UNIX_`? Perhaps you should be looking for better alternatives to those, like `__has_include()` or `__has_feature()` (depending on compiler support). Or autoconf. – Ken Thomases Feb 20 '16 at 22:28
  • See also: [Macro `__unix__` not defined in MacOS X](https://stackoverflow.com/questions/7063303) – hippietrail Apr 06 '21 at 04:31

1 Answers1

4

POSIX requires _POSIX_VERSION to be defined in <unistd.h> (also accessible via sysconf(_SC_VERSION)), so try that.

ninjalj
  • 42,493
  • 9
  • 106
  • 148
  • Ok, but before including I have to check I am on a POSIX system, otherwise that file will not be available. And should not be a small file to include... – Pietro Oct 28 '11 at 23:59