2

I've been told before (rightly or wrongly) that I should be using various older standards of C and C++. For example in a Uni module I did on C this year we had to use ANSI C (which I believe is C89?). Other times I've been told to use C99. Every time I'm told either of these, the reason given is that C11 is not safe to use, due to new features that may not be supported by every compiler etc. (I'm not a massive expert on this so explanation would be great).

It seems ludicrous to me that a standard is still not widely used 3 years after its release. Are these people wrong or is it genuinely a bad Idea to use C11 and C++11?

Matthew Wilkins
  • 1,335
  • 2
  • 12
  • 12
  • 3
    There can be quite a long lag between the release of a language standard and its adoption by compiler writers/vendors. Having said that, a C89 requirement is ludicrous - C99 is probably the best bet for routine use currently. – Paul R Jul 25 '14 at 10:10
  • You don't use a standard. You use a compiler. The compiler implements a set of standards. For example, if you bought your compiler four years ago, obviously it won't support C++11. You need to know the set of language standards supported by your compiler (or typically, the newest version of the standard which it supports; or if it is supported partially, which features are supported and which are not). After you know this information you can choose whether you want to use it or not. This latter part is opinion based. – Daniel Daranas Jul 25 '14 at 10:13

2 Answers2

3

Neither, both... the bane of legacy.

No you should use the newest tools available on your platform and that are compatible with the other elements in the system. New tools allow for "better" programming, safer programs, more concise programs, etc.

Yes you should use older tools, well, very simply, a lot of work is maintenance. Some of it will be on very old systems... being familiar with the issues of the tools will help when changes need to be made.

Your target audience (people and systems) will dictate what tools to use and what tools to support. The lowest common denominator almost always wins.

For the same reasons, I think this is the principle motivation for backwards compatibility. If the new tools don't break the old code, then the progression forward is eased.

In general, it is a good idea to use the newer language features with new compilers. There is a general move within the industry to support newer languages (even before the standard is final, e.g. clang and gcc with the upcoming C++14).

Niall
  • 30,036
  • 10
  • 99
  • 142
2

One of the major C compiler vendors, Microsoft, have stated that they do not intend to support the evolving C standard; they supply a C90 compiler and their C++ compiler will compile the C subset of the current C++ standard.

If you do not need your C code to compile on Windows, or you can use a non-Microsoft compiler, then you should feel free to use C11.

In any case, since the C subset of C++11 is closer to C11 than it is to C90, it makes more sense to learn the current C standard and the subset of that standard that is compatible with the current C++ standard.

Community
  • 1
  • 1
ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • Apparently they changed their minds since VS 2013, see http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx – Grzegorz Szpetkowski Jul 25 '14 at 10:22
  • @GrzegorzSzpetkowski the C99 library is required for C++11 conformance, so they didn't really have a choice :) – ecatmur Jul 25 '14 at 10:24
  • 2
    They introduced support for language features like _compound literals_ and _designated initializers_ as well, I don't think it's correlated with C++11 or even C++14. – Grzegorz Szpetkowski Jul 25 '14 at 10:28
  • @GrzegorzSzpetkowski from what I remember of the coverage at the time the big (claimed) motivation was to allow VS to compile major cross-platform open-source projects (ffmpeg was mentioned a lot at the time). – Nigel Harper Jul 25 '14 at 10:47