Mail Archives: djgpp/2002/07/23/13:16:51
dshnv <dshnv AT www DOT com> wrote:
> When I have a source file like this:
> #include <stdio.h>
> char global_data[100] = { 0 };
> int global_bss;
> int main()
> {
> int foo, bar;
> printf("%d\n", foo );
> }
> and I perform a objdump file.o, I don't see a _foo or a _bar in the
> relocation or symbol table.
Of course you don't. Return to your C textbook and read about the
difference between static and automatic variables to see why.
> I already know that global_bss does not appear in the .bss but is
> defined as member of the [common] section. But I have to reserve
> memory for it anyway, so I thought of appending it at the end of the
> .bss.
You're looking at the wrong file, I think. Note that file.o is
produced by the compiler alone. It's the *linker* which will proceed
to put things from [common] into .bss, after having checked for
duplicates, which it would unite.
It may be best to avoid (i.e.: forbid) uninitialized,
non-"static"-qualified file-scope variable definitions like your
"global_bss". Require them to either be initialized, or explicitly
labelled as private ("static"), or as "extern" to make them
declarations instead of (tentative) definitions.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -