Blog

Tag Archives: undefined-behavior

The overflow when converting from float to integer is undefined behavior
Pascal Cuoq on 9 October 2013

Integer overflows in C A previous post on this blog was a reminder that in C signed integer arithmetic overflow is undefined behavior. In contrast the behavior of overflows in conversions from integer type to signed integer type is implementation-defined. The C99 standard allows for an implementation-defined signal to be...

Read More

From Pascal strings to Python tuples
Pascal Cuoq on 31 July 2013

Quiz time What does the program below do? #include <stdio.h> int main(){ struct { int t[4]; int u; } v; v.u = 3; v.t[4] = 4; printf(\v.u=%d" v.u); return 0; } Two answers are “it prints v.u=4” and “it prints v.u=3”: $ gcc t.c && ./a.out v.u=4 $ gcc -O2...

Read More

Attack by Compiler
Pascal Cuoq on 20 May 2013

The title of this post, “Attack by Compiler”, has been at the back of my mind for several weeks. It started with a comment by jduck on a post earlier this year. The post's topic, the practical undefinedness of reading from uninitialized memory, and jduck's comment, awakened memories from a...

Read More

Making oughts from ises
Pascal Cuoq on 13 April 2013

A previous post discussed the nature of uninitialized and indeterminate memory throughout the C standards. The argument was “avoid using uninitialized data even if you think you know what you are doing; you may be right but regardless your compiler might think it knows what you are doing and be...

Read More

Reading indeterminate contents might as well be undefined
Pascal Cuoq on 13 March 2013

Warning: on a punctiliousness scale ranging from zero to ten, this post is a good nine-and-a-half. There was no tag for that, so I tagged it both “C99” and “C11”. The faithful reader will know what to expect. There is a bit of C90, too. To summarize, it may appear...

Read More