News for hackers. Stuff that matters.
Re:The Shortest Crashing C Program by bnegreve on Friday May 24, 2013 @09:57AM (#5762743)
But global variables are static.
Re:The Shortest Crashing C Program by deweerdt on Friday May 24, 2013 @10:00AM (#5762766)
No, they're not. In fact, if the program used 'static main;' instead, it wouldn't even compile because the 'main' symbol wouldn't be visible by the linker.
Re:The Shortest Crashing C Program by anarion on Friday May 24, 2013 @10:14AM (#5762867)
Yes they are ! Global variables have static storage duration and are therefore default initialized. Be careful with the word 'static' which does not always correspond to the the keyword static which has several meaning ! When used with a global variable the static keyword has not the same meaning as static storage duration". It only means no external linkage.
Re:The Shortest Crashing C Program by to3m on Friday May 24, 2013 @10:14AM (#5762871)
Both have so-called "static storage duration", which is what influences the initial value. See C99 standard, section 6.2.4 paragraph 4:

"An object whose identifier is declared with external or internal linkage, or with the storage-class specifier `static' has /static storage duration/. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup."

The default initial value of objects with static storage duration is dealt with in 6.7.8 paragraph 10. Basically: pointers set to NULL, non-pointers have all bits reset, aggregates thus recursively.

Re:The Shortest Crashing C Program by bnegreve on Friday May 24, 2013 @10:08AM (#5762819)
Ok, well I agree. I mean global variables are not created dynamically. There is room reserved for them in the data segment which is initialized to 0. Can you give me an example where a global variable isn't initialized to 0? Your valgrind example doesn't say much about the value in the main variable ..

Edit, @deweerdt: ok :)

Re:The Shortest Crashing C Program by deweerdt on Friday May 24, 2013 @10:11AM (#5762842)
@bnegreve can't reply to your post, but i was mistaken. externally visible symbols are also initialized to 0