Which C99 features are available in the MS Visual Studio compiler?

Fortunately, Microsoft’s stance on this issue has changed. MSVC++ version 12.0 (part of Visual Studio 2013) added support for _Bool type. Compound literals. Designated initializers. Mixing declarations with code. __func__ predefined identifier. You can check the _MSC_VER macro for values greater than or equal to 1800 to see whether these features are supported. Standard library … Read more

How to wrap printf() into a function or macro?

There are 2 ways to do this: Variadric macro #define my_printf(…) printf(__VA_ARGS__) function that forwards va_args #include <stdarg.h> #include <stdio.h> void my_printf(const char *fmt, …) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); } There are also vsnprintf, vfprintf and whatever you can think of in stdio.

Is there a GCC keyword to allow structure-reordering?

Previous GCC versions have the -fipa-struct-reorg option to allow structure reordering in -fwhole-program + -combine mode. -fipa-struct-reorg Perform structure reorganization optimization, that change C-like structures layout in order to better utilize spatial locality. This transformation is affective for programs containing arrays of structures. Available in two compilation modes: profile-based (enabled with -fprofile-generate) or static (which … Read more

Anonymous union within struct not in c99?

Anonymous unions are a GNU extension, not part of any standard version of the C language. You can use -std=gnu99 or something like that for c99+GNU extensions, but it’s best to write proper C and not rely on extensions which provide nothing but syntactic sugar… Edit: Anonymous unions were added in C11, so they are … Read more

state machines tutorials [closed]

State machines are very simple in C if you use function pointers. Basically you need 2 arrays – one for state function pointers and one for state transition rules. Every state function returns the code, you lookup state transition table by state and return code to find the next state and then just execute it. … Read more