Subject: Re: __unix__ macro
To: Julio Merino <>
From: Jason R Thorpe <>
List: netbsd-users
Date: 08/26/2002 08:21:04
On Mon, Aug 26, 2002 at 12:53:18PM +0200, Julio Merino wrote:

 > While trying to compile OpenCM, I saw that __unix__ was not defined during
 > compilation... I've tried the following program in NetBSD, OpenBSD and FreeBSD:
 > #include <stdio.h>
 > int main() {
 > #ifdef __unix__
 > printf("defined\n");
 > #else
 > printf("not defined\n");
 > #endif
 > return 0;
 > }
 > Both in FreeBSD and OpenBSD it says 'defined', but in NetBSD I get 'not defined'.
 > Why is this?

On FreeBSD and OpenBSD, their compilers also do -Dunix, which is a
violation of ISO C namespace rules.  Due to the mechanics of builtin -D's
in GCC, the same code that causes -Dunix to be defined also causes -D__unix
and -D__unix__ to be defined.

Since NetBSD does not do -Dunix (since doing so is wrong in ANSI and
ISO C), it also does not do -D__unix__.

Any program which relies on "unix" or "__unix__" being defined is really
broken, since there are quite a number of Unix systems which do NOT define
those macros.

        -- Jason R. Thorpe <>