Integer overflow in C: standards and compilers

Take a look at -ftrapv and -fwrapv: -ftrapv This option generates traps for signed overflow on addition, subtraction, multiplication operations. -fwrapv This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables other. This option is enabled by … Read more

is size_t always unsigned?

Yes. It’s usually defined as something like the following (on 32-bit systems): typedef unsigned int size_t; Reference: C++ Standard Section 18.1 defines size_t is in <cstddef> which is described in C Standard as <stddef.h>. C Standard Section 4.1.5 defines size_t as an unsigned integral type of the result of the sizeof operator

Is a compiler allowed to add functions to standard headers?

In 4. “Conformance” §6, there is: A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program. with the immediate conclusion in a footnote: This implies that a conforming implementation reserves no identifiers other than those explicitly reserved in this International Standard. The reserved … Read more

Why is using exit() considered bad? [duplicate]

Just blindly calling exit() somewhere in your program is considered bad for a simple reason: It does not properly shutdown other threads (they just get terminated), it does not properly flush all buffers (stdio files are flushed) and guarantee a consistent and valid state of permanent/shared resources (files/shared memory/other ways to communicate). Still, if you … Read more

ISO C++ standard draft

For a while, n3291 was available from the obvious URL (just search and replace n3242 with n3291 in the Wikipedia link). But I guess somebody decided that was too close to the final version so it is no longer accessible. Thus Wikipedia does not link to it because there is nothing to link to. I … Read more