GCC options for strictest C code? [duplicate]

I’d recommend using: -Wall -Wextra -std=c89 -pedantic -Wmissing-prototypes -Wstrict-prototypes \ -Wold-style-definition You should compile with -O as well as -g as some warnings are only available when the optimizer is used (actually, I usually use -O3 for spotting the problems). You might prefer -std=gnu89 as that disables fewer extensions in the libraries. OTOH, if you’re … Read more

ANSI C vs other C standards

I don’t understand why/if I should pick the c89 standard versus a newer standard like c99 (which is the newest I assume). A couple of reasons: 1) gcc’s C99 support is not quite complete, whereas its C89 support is. That’s why C89 (with GNU extensions) is the default. So if you’re an absolute stickler for … Read more

What does static mean in ANSI-C [duplicate]

Just as a brief answer, there are two usages for the static keyword when defining variables: 1- Variables defined in the file scope with static keyword, i.e. defined outside functions will be visible only within that file. Any attempt to access them from other files will result in unresolved symbol at link time. 2- Variables … Read more

String termination – char c=0 vs char c=’\0′

http://en.wikipedia.org/wiki/Ascii#ASCII_control_code_chart Binary Oct Dec Hex Abbr Unicode Control char C Escape code Name 0000000 000 0 00 NUL ␀ ^@ \0 Null character There’s no difference, but the more idiomatic one is ‘\0’. Putting it down as char c = 0; could mean that you intend to use it as a number (e.g. a counter). … Read more

What is the significance of January 1, 1601?

Because 1/1/1601 was the start of the epoch. Take it from Raymond Chen: Why is the Win32 epoch January 1, 1601?🕗 The FILETIME structure records time in the form of 100-nanosecond intervals since January 1, 1601. Why was that date chosen? The Gregorian calendar operates on a 400-year cycle, and 1601 is the first year … Read more

Why doesn’t ANSI C have namespaces?

For completeness there are several ways to achieve the “benefits” you might get from namespaces, in C. One of my favorite methods is using a structure to house a bunch of method pointers which are the interface to your library/etc.. You then use an extern instance of this structure which you initialize inside your library … Read more

What is the difference between C, C99, ANSI C and GNU C?

Everything before standardization is generally called “K&R C”, after the famous book (1st edition and 2nd edition), with Dennis Ritchie, the inventor of the C language, as one of the authors. This was “the C language” from 1972-1989. The first C standard was released 1989 nationally in USA, by their national standard institute ANSI. This … Read more

How to convert an enum type variable to a string?

The naive solution, of course, is to write a function for each enumeration that performs the conversion to string: enum OS_type { Linux, Apple, Windows }; inline const char* ToString(OS_type v) { switch (v) { case Linux: return “Linux”; case Apple: return “Apple”; case Windows: return “Windows”; default: return “[Unknown OS_type]”; } } This, however, … Read more