Mail Archives: djgpp/2000/12/19/07:48:20
On Mon, 18 Dec 2000, Kevin Mitchell wrote:
> Yes, it *is* very easy to write simple test programs and see what they
> print. I didn't even have to do that... as I had, in a previous exercise,
> printed out the values of pointers for all the fundamental types. Yes, I did
> notice the striking tendency of all pointer addresses of all types to be
> divisible by 32. However... that doesn't really answer the question
> (B.Stroustrup's question, that is).
What question is that, exactly?
> I don't think that, just because all the pointers I'm creating are divisible
> by 32, that all the pointers in this system *will* be....
What you see is how the compiler and the linker allocate addresses for
variables of different types. Once you've seen the same alignment in
several different cases, there's no reason to believe that it's not
the general rule. You are not looking for subtle exceptions, anyway.
> After all, I
> theorize... maybe it's a limitation of my hardware... or maybe it's just
> convenient under the current environment settings... or maybe it's being set
> that way because I have all the debugging information turned on... maybe it
> will change if I "optimize" the compilation... or remove "debugging"
> information... or just run it on a different computer.
You could try all that and see. Another machine and a few different
compilation switches is all you need to test. (You don't need to try
all of the compilation switches, because you are only interested in
the ``normal'' code produced by the compiler in the usual cases.)
> Actually, I'm hoping that somebody involved in the development of my
> compilation/linking/etc tools knows...
If you want to talk to compiler and linker developers, you need to
post questions to the relevant discussion forums.
> and has written it down somewhere for the benefit of those less
> knowledgeable... Actually, I'm rather shocked that
> the answer wasn't really easy to find.
The reason is that most users indeed don't need to worry about such
low-level stuff. All you need to know is that you are working on a
32-bit machine, so pointers and int's should be expected to have a
4-byte alignment, double's will have 8-byte alignment, etc. The rest
should be up to the person who configures and builds the compiler and
the linker to figure out and set them up correctly.
- Raw text -