Linux compilation; BSS segment memory initialized to 0?
In tests, the memory in the BSS part of the program I ran was always initialized to zero before I wrote anything there. Is this a coincidence, or did the system “clean” these memory pages before handing them over to me? I’m using the nasm assembler on Ubuntu (if this might be different).
Your application’s executable file (ELF) has a BSS segment size information, and when it starts, the kernel allocates a block of memory for the BSS segment and cleans it up to 0. This is defined by ABI (Application Binary Interface), so you don’t have to worry about making things different on different machines.