3 ms·
See my post: https://news.ycombinator.com/item?id=5762363 https://news.ycombinator.com/item?id=5762363 main will have a value of zero, and 0x600864 will presum
by to3m 13y ago
See my post: https://news.ycombinator.com/item?id=5762363 https://news.ycombinator.com/item?id=5762363
main will have a value of zero, and 0x600864 will presumably be &main (it's not the initial arbitrary value of main).
Auto variables are left uninitialized so that they don't have to be given a value when they're allocated. It's for efficiency, and it makes the compiler simpler to have this blanket rule rather than have it try to figure out the minimal initializations necessary (which probably isn't even possible). But this ocnsideration doesn't apply to globals or statics, because the initialization can be done at compile time, or (sometimes, in C++) on program startup.
- lgeek 13y ago> the initialization can be done at compile time, or (sometimes, in C++) on program startup With ELF binaries for C programs it's done at startup as well. The data segment is created as having memory size SIZEM and file size SIZEF. If SIZEF < SIZEM, memory from SIZEF to SIZEM is set to 0.