Using M_PI with C89 standard

A conforming standard library file math.h is not only not required to, but actually must not define M_PI by default. In this context ‘by default’ means that M_PI must only get defined through compiler-specific tricks, most often undefined behavior through the use of reserved identifiers. Just define the constant yourself (you can use the name … Read more

Variable declaration placement in C

It compiles successfully because GCC allows the declaration of s as a GNU extension, even though it’s not part of the C89 or ANSI standard. If you want to adhere strictly to those standards, you must pass the -pedantic flag. The declaration of c at the start of a { } block is part of … Read more

What is the behavior of integer division?

Will result always be the floor of the division? What is the defined behavior? Not quite. It rounds toward 0, rather than flooring. 6.5.5 Multiplicative operators 6 When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.88) If the quotient a/b is representable, the expression (a/b)*b … Read more