Code: Select all
extern char **environ;
static char ***p_environ = &environ;
When relocated to form a static binary?
or when _init() traverses _init_array?
It shouldn't be in .bss as it is not zero
Code: Select all
extern char **environ;
static char ***p_environ = &environ;
Code: Select all
static int a = 100;
if (a != 100) {
fail....
}
Don't assume, check.dchapiesky wrote:assuming I have my sections correct....
It should not, however check your .data section in the .o file with objdump and then compare with results of objcopy-ing it.dchapiesky wrote:would objcopy'ing to binary format negate the initialization?
True for C. Not true for C++.iansjack wrote:I believe that static variables can only be initialized using constant literals.
It stands out more. But static is sufficiently visible alone (first thing on a line).iansjack wrote:I find it good practice to always explicitly assign an initial value to a static variable within a function.
The code snippet is from newlib's getenv_r.c file...iansjack wrote:I believe that static variables can only be initialized using constant literals. I find it good practice to always explicitly assign an initial value to a static variable within a function.