Better Save Space

Two versions of the same program differ in one character. The array is 4 MiB.

/* version A */
static int table[1048576];

/* version B */
static int table[1048576] = { 1 };

One of these produces an executable file on disk that is roughly 4 MiB larger. Which one, and why?

A

Neither. Both arrays are created by the loader at run time, so neither contributes to the file size.

B

B. Any nonzero initializer puts the whole object in .data, which is stored byte for byte in the file. A lands in .bss, which has a section header but occupies no file space.

C

B, but only by about 4 bytes, since the toolchain stores the initialized element and lets the loader zero the rest.

D

A. An uninitialized array must be zeroed before main runs, so the zeros are written into the file for the loader to copy.