[sf-lug] K & R errata

Alison Chaiken alchaiken at gmail.com
Tue Jul 5 00:38:27 PDT 2011

Thanks to everyone for a fascinating discussion.     I note that there's an
Erlang tutorial during OSCON:


I'm already signed up.

jim <jim at systemateka.com> writes:

I think declaring a variable is
type identifier, e.g.
int i;
and defining a variable is
type identifier assign value, e.g.
int j = 3;

  the compiler may set up images of segments for
machine code (the text segment), data, and the stack(s)
during its compile phase or defer that work until it's
in the optimizing phase.
   regardless, it may "allocate" memory for a declared
variable or not, depending on the variable's status as
global or as local within some function.
Regarding whether storage is allocated for declared variables

I've noticed that declaring

int a[100];

increases the size of a binary while

int a = (int *) malloc(100*sizeof(int));

does not.        That's what you'd expect, as one set of numbers is
statically allocated, while the other is allocated dynamically.   They
should both get initialized to zero, which means that they should go into
the .bss section of the ELF file (the executable) that the linker produces
at the end of compilation.

   the language designers themselves were careful to
keep I/O and platform and compiler designs out of the

True dat, but if I understand correctly, the ELF format used by Linux
executables (not just C ones) does constrain the allocations.   readelf is a
command that comes with binutils and allows examination of precisely what is
inside executables.    Hallinan's _Embedded Linux Primer_ (far and away my
favorite book) has helpful comments about using binutils to answer questions
like this in Chapter 13.   The Hallinan book is available as a free
download, but you should buy a hardcopy so that you can sleep with it under
your pillow.

"valgrind --tool=memcheck" is the other gold-standard Linux memory checker,
as is well-known.

BTW Jim, I don't mean to be a flamer, but capitalization does help with

Alison Chaiken
(650) 279-5600  (cell)
Spend much time at the cutting edge and you're liable to get cut.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://linuxmafia.com/pipermail/sf-lug/attachments/20110705/9c5e8a9e/attachment.html>

More information about the sf-lug mailing list