GCC: General Macro for BSD

Is there a universal macro for any BSD system. I am currently on FreeBSD where __FreeBSD__ is defined. It looks like on NetBSD systems __NetBSD__ is defined. I have tried using __BSD__ but doesn't appear to exists. Is there a universal way of testing if you are using any BSD system with GCC? According to this page I should be able to use BSD, but this is not working for me.

test.c:

#include <stdio.h>

int main(void) {
#if defined(unix)
    printf("Hello unix!\n");
#endif

#if defined(UNIX)
    printf("Hello UNIX!\n");
#endif

#if defined(__unix__)
    printf("Hello __unix__!\n");
#endif

#if defined(__UNIX__)
    printf("Hello __UNIX__!\n");
#endif

#if defined(__BSD__)
    printf("Hello __BSD__!\n");
#endif

#if defined(BSD)
    printf("Hello BSD!\n");
#endif

#if defined(__FreeBSD__)
    printf("Hello FreeBSD!\n");
#endif

#if !defined(__FreeBSD__)
    printf("Not Hello FreeBSD!\n");
#endif

#if defined(__NetBSD__)
    printf("Hello NetBSD!\n");
#endif

#if defined(__WIN32__) || defined(__WIN64__)
    printf("Hello Windows!\n");
#endif

#if defined(__LINUX__)
    printf("Hello Linux!\n");
#endif
    }

Output:

--- Edit ---

Sorry, I wasn't paying attention. I need to include [cmd]sys/param.h[/cmd].

--- Note ---

I am also posting this question to the FreeBSD forums: https://forums.freebsd.org/viewtopic.php?f=35&t=47769&p=266740\#p266740

You can do it like #if defined(__SOMETHING__) || defined(__SOMETHINGELSE__) || defined(__THIRDTHING__)

Thanks Corona, I realize that. I just wanted to test each macro individually.

cpp -dM /dev/null
1 Like

Thank you achenle. That command is very helpful. Is there a way to include the defines "sys/param.h" in that command?

cpp -dM <<"EOF"
#include <sys/param.h>

/* as much more code as you want */
EOF
1 Like

Thank you Corona, perfect. That helps me understand stdin a bit better as well.

1 Like