Live data from Hacker News

Why does the C preprocessor interpret the word “linux” as the constant “1”?

stackoverflow.com

1–10 of 60 posts

Re: Why does the C preprocessor interpret the word “linux” as the constant “1”?

#3
post #2

While I can't imagine much discussion here that couldn't occur on SO, I did want to say thank you for posting this. I found it quite interesting.

+1, I love those interesting Stack Overflow (and Stack Exchange) posts that started to appear here every other week. I always learn something new/interesting from them. Thank you dcro :).

Re: Why does the C preprocessor interpret the word “linux” as the constant “1”?

#7
post #3
post #2

While I can't imagine much discussion here that couldn't occur on SO, I did want to say thank you for posting this. I found it quite interesting.

+1, I love those interesting Stack Overflow (and Stack Exchange) posts that started to appear here every other week. I always learn something new/interesting from them. Thank you dcro :).

no doubt the SO question will soon be closed as "not a question" or "too interesting" or some other draconian response :(

Re: Why does the C preprocessor interpret the word “linux” as the constant “1”?

#8
post #7
post #3

Earlier quoted context omitted.

+1, I love those interesting Stack Overflow (and Stack Exchange) posts that started to appear here every other week. I always learn something new/interesting from them. Thank you dcro :).

no doubt the SO question will soon be closed as "not a question" or "too interesting" or some other draconian response :(

They'll lock it to keep newbies away if nothing else, but I doubt it'll get shut down. This is a "good fit" for the Stack sites though - it's a direct question with one single direct answer.

Re: Why does the C preprocessor interpret the word “linux” as the constant “1”?

#9
post #5

If you're in the habit of writing "struct sockaddr_in sin;", you'll probably be tempted to write "struct sockaddr_un sun;". Just don't expect that code to compile on Solaris.

Is that just hardcoded into the preprocessor itself? Or is part of ANSI C. Wondering if the MS C++ compiler will do this well.
Post reply on HN