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

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

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