Reputation: 447
Out of C18, C11, C99, and ANSI C, which standard should I (currently) stick to, and why? What is the best way to find out which compilers support which standards? How does this choice differ for different programming domains?
Upvotes: 0
Views: 6256
Reputation: 26703
You most likely are asking for a decision which you have to make yourself and which will only affect you. Let me nevertheless put it into a wider context. If you are a professional then in whatever project you are contributing to, there is (or should be) one person responsible for that decision. I consider it obvious that for a larger project it is most important that everybody uses the same compiler version and standard; to avoid unpredictable differences.
This does of course not mean that intentional testing and comparing of behaviour should be skipped; but I assume that in a project which has somebody for making the compiler/version/standard decision there also is an planned activity for that.
So, if there is a person for the decision defined: Do what that person decides. Maybe offer to review their decision or to participate in the testing and comparing.
In case you are free to decide (because you are that person or because the whole project is just you), then at first go with the latest revision (like other answers recommend), assuming you do not happen to have good reasons to the contrary.
Then, when another one becomes available, redecide consciously; I recommend to tend to stay with the one you started with, if there are no relevant benefits to be had from newer one.
That is because in case of a (professional multi-person) project with a non-negligible code base, deciding to use a newer compiler (implied by a newer standard being supported) is risky. It would at least make a regression test necessary.
Upvotes: 0
Reputation: 31296
Out of C18, C11, C99, and ANSI C, which standard should I (currently) stick to, and why?
In general the latest. Use the latest unless you have some argument against.
One argument against using C18 is that the documentation does not seem to be freely available yet, but C11 is. Well, freely and freely. At least they are here: https://port70.net/~nsz/c/ Note that these are not the final ones, but for most purposes they are good enough. Thanks to @Lundin and @JohnBode for pointing it out.
Another argument is that there may be platforms you want to support where a newer standard is not supported.
And I would strongly advice against ANSI unless you have no other choice. The C99 version was a very big improvement. After that, there are some nice new features, but the biggest change was C99.
What is the best way to find out which compilers support which standards?
Google. Or look in the documentation for the compilers you are interested in. However, be aware that some compilers may not be 100% compliant with a certain C version, even if they claim to be.
Upvotes: 5
Reputation: 4307
In my experience, this is often a matter of organizational policy rather than personal preference. And the reasons for the organizational policy are often not technical - they're tied up with support contracts and staff training and matters like that.
If you have the good fortune to be able to make the choice entirely yourself, you still need to consider matters such as the range of platforms you want to support, and the currentness of the compilers that will be available to people who might have to build your code, other than yourself.
If you have a complete free hand in this area, consider yourself lucky ;)
Upvotes: 1
Reputation: 134286
Usually, the latest standard, as soon as it's released, supersedes all other existing standards. So, theoretically, it's the latest one available at any time.
However, not all compilers will be up-to-date to support the latest standard revision - the practical answer is: whichever is the latest version supported by your environment, is usually best to use.
Upvotes: 4