c-faq

Why can't I convert 'char**' to a 'const char* const*' in C?

The following code snippet (correctly) gives a warning in C and an error in C++ (using gcc & g++ respectively, tested with versions 3.4.5 and 4.2.1; MSVC does not seem to care): char **a; const char** b = a; I can understand and accept this. The C++ solution to this problem is to change b to be a const char * const *, which disallows ...

Why isn't sizeof for a struct equal to the sum of sizeof of each member?

Why does the 'sizeof' operator return a size larger for a structure than the total sizes of the structure's members? ...

Ways to ASSERT expressions at build time in C

I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers). However, I'm concerned that with the volume of changes I m...

Understanding sizeof(char) in 32 bit C compilers

(sizeof) char always returns 1 in 32 bit GCC compiler. But since the basic block size in 32 bit compiler is 4, How does char occupy a single byte when the basic size is 4 bytes??? Considering the following : struct st { int a; char c; }; sizeof(st) returns as 8 as agreed with the default block size of 4 bytes (since 2 blocks are a...