GCC: General Macro for BSD


 
Thread Tools Search this Thread
Top Forums Programming GCC: General Macro for BSD
# 1  
Old 08-25-2014
BSD [Solved] 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:
PHP Code:
#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:
Quote:
Hello FreeBSD!
Hello All!


--- 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...266740#p266740

Last edited by AntumDeluge; 08-25-2014 at 04:12 PM.. Reason: Solved
# 2  
Old 08-25-2014
You can do it like #if defined(__SOMETHING__) || defined(__SOMETHINGELSE__) || defined(__THIRDTHING__)
# 3  
Old 08-26-2014
Thanks Corona, I realize that. I just wanted to test each macro individually.
# 4  
Old 08-26-2014
Code:
cpp -dM /dev/null

This User Gave Thanks to achenle For This Post:
# 5  
Old 08-27-2014
BSD

Thank you achenle. That command is very helpful. Is there a way to include the defines "sys/param.h" in that command?
# 6  
Old 08-27-2014
Code:
cpp -dM <<"EOF"
#include <sys/param.h>

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

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 08-28-2014
Thank you Corona, perfect. That helps me understand stdin a bit better as well.
This User Gave Thanks to AntumDeluge For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

2. Solaris

Installing gcc - recieve error message gcc : cannot execute

AIM- Install Oracle 11g on Solaris using VMWare Steps 1.Logged on as root 2.Created subfolders à /usr/local/bin & /usr/local/bin/gcc 3.Downloaded gcc & libiconv & unzipped them on my harddrive & burnt them on CD 4.Copied files from CD to /usr/local/bin/gcc 5.Terminal (root) à pkgadd -d... (8 Replies)
Discussion started by: Ackers
8 Replies

3. BSD

for linux and BSD users interested in Unix system V/bsd

for all you unix/linux interested heres an online book for free that covers the basics of BSD SysV Unix commands and applications . giving the average linux user a perspective on the differences in context of the two operating systems and for BSD users covers material as a refernce guide. ... (0 Replies)
Discussion started by: moxxx68
0 Replies
Login or Register to Ask a Question