3

When googling 'check operating system c', I immediately see a Stack Overflow page:

How do I check OS with a preprocessor directive?

But then I scroll down and see more. And in the 'Related Questions' area, I see even more.

Are these all duplicates? If not, why not? If so, can we get them closed?

2 Answers 2

5

What you may notice upon reading all of these, is that the quality of the answers is all over the place. The most important thing is to recognize which one that has the highest quality and see if it could serve as a "canonical duplicate". This one appears to be good:

How to detect reliably Mac OS X, iOS, Linux, Windows in C preprocessor?

The most popular answer has been updated and maintained by all kinds of people, almost as if it was a community wiki. It covers a lot of cases. Also notably, the community seems to have decided that this is a canonical question/answer, judging by the very high number of up-votes.

Now if you really could be bothered, you could run off and find all duplicates to that question. There's gonna be a lot of them. You could close-vote as duplicates or if you don't have enough rep for that, flag them. However, as suggested in another answer, the best way may be to find somebody with a gold badge, as they can close all duplicates instantly, without involving so many other people in the processes. Or well, let them find you, I did :) I've gone through the links you provided.


You have to keep in mind that some language- or OS-specific answers may exist, for example I wouldn't close this a duplicate: How can I check OS version (Windows) with preprocessor directives?. Because even though the question itself seems to be a duplicate, it offers an alternative answer in C++ specifically, that doesn't involve the preprocessor. Seems like it could potentially be worth preserving, so I wouldn't close it.

Determine OS during runtime is a different question since it is explicitly about run-time checks and not compile-time (which is kind of weird, it's not like your OS is going to change in the middle of program execution...). I don't quite see how this question makes sense, but it doesn't seem to be a duplicate.

Identify the platform linux or windows using C/C++ code seems to be a duplicate of the canonical one. The answers are not as exhaustive and overall of lower quality. Closed as duplicate.

Why does the C preprocessor interpret the word “linux” as the constant “1”? is another question, not really about to how to find the OS, but rather about some historical oddities related to Unix/Linux specifically. Not a duplicate.

How do I check OS with a preprocessor directive? is definitely a duplicate and there are a few nice answers there too. This could potentially have been a canonical duplicate too, although the first one I linked covers the same things. However, we never need 2 canonical duplicates.
But when closing something with this much attention and up-votes, I would be extra careful. Most of the answers are rather mediocre, including the accepted one. But this answer is good and actually covers a few things that the above mentioned canonical duplicate doesn't, namely the __MACH__ define and FreeBSD. Ideally these should be integrated in the canonical duplicate if we were to close this answer. I personally know next to nothing about those OS, so I'm not confident enough to determine if these defines are relevant. I'm therefore hesitant to close this as a duplicate.

Course of action for that last one could be to sweet talk some diamond mod into performing a manual topic merge, so that the single good answer is preserved.

11

First, you should check the question completely.
Title similarity does not means it is a duplicate.

If you are sure that this is a duplicate, check for the question with best answer* and for all other questions, raise a duplicate flag.

Alternatively,

you can go to the C chat room and post the post links there. Then someone holding a gold badge in C can review and close it as a duplicate.

* I prefer to say the best one instead of old one after looking into the comment by J. Steen and as suggested in this post Should I flag a question as duplicate if it has received better answers?

4
  • 16
    Don't check for the oldest question. Check for the best question, with the best answers.
    – J. Steen
    Mar 5, 2017 at 8:23
  • thanks for the information @J.Steen, i edited question. Found something related to your comment meta.stackoverflow.com/questions/251938/…
    – Sagar V
    Mar 5, 2017 at 8:43
  • 5
    Also, similar title can cause people to not be able to identify which of them has the answer they are looking for. Change them into some more descriptive/less vague ones.
    – Braiam
    Mar 5, 2017 at 21:52
  • I think this is kind of a blanket statement that doesn't attempt to answer the question at all.
    – CodeCaster
    Mar 7, 2017 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .