tags:

views:

629

answers:

6

I usually write C code in C89, now some features of C99 (like intxx_t or __VA_ARGS__ or snprintf) are very useful, and can be even vital.

Before I more my requirements from C89 to C99 I wanted to know which of C99 features were widely supported and which ones were not widely supported or even considered harmful.

I know we could just check our target compiler support, but this would narrow our support a lot, and as this is for open source software, I'd prefer having a wider support.

For example, we use Solaris (suncc) compiler and gcc, but there might be other compiler we would move out of the way while we could keep compatibility with very little efforts.

For example, I never worked on Windows nor I know anything about Windows compilers, but it would be good to keep Windows compatibility.

+3  A: 

goto is still considered harmful.

wallyk
+1 for the classic reference.
ChrisV
Oh, it's fun to put one in each program just to annoy purists. But please, have it point downward and not upward.
DigitalRoss
+2  A: 

Well, gcc is basically going to be gcc regardless of which desktop OS you're targeting.

Visual C++, being primarily a C++ compiler, isn't quite as concerned with the C99 spec. stdint.h does declare your favorite intxx_t macros. __VA_ARGS__ is available. _Bool, _Complex, and _Pragma aren't implemented on the Microsoft Visual C++ compiler. I'm pretty sure %a fields in printf/scanf haven't been implemented, though maybe VC2010 handles them. snprintf is present, but has a leading underscore and slightly different semantics.

Short answer: The "easier" a C99 feature is to implement without changing compiler grammars or replumbing the standard library, the more likely VC++ is to support it. If there's a conflict between C99 and C++, expect C++ to win.

ChrisV
+1  A: 

A number of C99 features are optional, so their lack isn't technically non-conforming. I won't distinguish below.

  • Hmm, win doesn't have <stdint.h>, although there is an open-source version of stdint.h for Microsoft. Even when the file is implemented, many of the individual types are missing.

  • Complex and imaginary support is often missing or broken.

  • Extended identifiers and wide characters can be problem points.

See this list of C99 feature issues in gcc.

DigitalRoss
Visual C++ 2010 has stdint.h.
ChrisV
Only 11 years late! *sigh*
Stephen Canon
A: 

The type generic maths functions from <tgmath.h> are not necessarily widely implemented, though they do seem to be provided with GCC 4.2.1 on MacOS X 10.6.2.

Jonathan Leffler
A: 

restrict became a keyword in C99. That is implementation encroaching on users' namespace. If you have a valid C89 program that contains the word restrict, you must change your program to make it work with C99. In other words: no backward compatibility. If they were going to break backward compatibility, they should have removed gets from the standard first.

Alok
A: 

Runtime sizeof is a nightmare of compiler's writers. So I consider is harmful.

osgx