Which most common extensions are there (or used) to ANSI C?
-
11-09-2019 - |
Question
You can put a link to comparison matrix or lists of extensions available to main compilers. If none of this is available, you could write a list of extension you use or like in your favorite compiler.
OTHER TIPS
C++/ISO-C style comments by far: //
Well, this depends on whether you mean C89 or C99 when you say "ANSI C". Since most mainstream implementations aren't fully C99-compliant yet, I'm going to assume C89.
In that case, I'd say (and not including specific APIs like POSIX or BSD Sockets):
long long
must be the most common extension;- followed by allowing accesses to
union
members other than the last written; inline
is probably up there;snprintf
is available in a lot of places;- allowing casting between function pointers and void pointers is widespread;
alloca
Edit: Ahh yes, how could I forget the ubiquitous //
style comment.
In one of the notorious compilers for embedded C, you can specify little- or big-endian for a struct type independently from the processor's preference. Very convenient for writing device drivers, if you remember not to access one of the fields through (say) an int*
that forgets the endianness.
Are you serious with the feature matrix thing? Do you think SO members have nothing better to do?
A number of compilers allow anonymous structs inside anonymous unions, which is useful for some things, e.g.:
struct vector3
{
union
{
struct
{
float x, y, z;
};
float v[3];
};
};
// members can now be accessed by name or by index:
vector3 v;
v.x = 1.0f; v.y = 2.0f; v.z = 3.0f;
v.v[0] = v.v[1] = v.v[2] = 0.0f;