Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Program won't crash when it should

Name: Anonymous 2012-01-16 3:24

(GCC C)
I ran a pointer over each member of an integer array, storing one character of input in each cell.

The program seems to consistently crash when I try to store X+3 or more characters, where X is the size of the array, but if I do not exceed X+2 it will not crash.

Why does it crashes exactly at the point it does, but not for X+1 or X+2?

Name: Anonymous 2012-01-16 20:50

>>40
This program is correct and does not feature any undefined behavior.

<stdio.h> is included so printf is defined as per the C standard library

The printf function is equivalent to fprintf with the argument stdout interposed before the arguments to printf.

The fprintf function returns when the end of the format string is encountered.

The return 0 in main is equivalent to calling exit with 0 as an argument which will flush all open streams with unwritten buffered data then close all open streams.


The requirement is that "At program termination, all data written into files shall be identical to the result that execution of the program according to the abstract semantics would have produced.", since stdout is flushed and closed the program writes the same data to stdout as the C abstract machine would at program termination so it's a conforming implementation.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List