Topic: Alignement in C/C++ (Was: Alignement)
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/12/10 Raw View
Steve Clamage wrote:
> There is no problem in defining "alignment" for a particular
> implementation or platform.
Right
> The problem is defining it in an implementation-neutral way.
> The above example isn't quite adequate for a segmented
> architecture, and fails to take into account validation built
> into some architectures (capability-based architectures, for
> example).
>
> The C++ standard tries to be implementation-neutral, and
> tries not to rule out unusual or innovative architectures.
> It therefore tries not to imply any particular mapping
> between addresses and pointers, and tries not to imply any
> particular characteristics of addresses. (Some characteristics
> are probably constrained by the required properties of integer
> types and arrays, however.)
>
> Ideally, the standard wouldn't mention the word "address" at
> all, but that doesn't seem possible. It acknowleges that some
> implementations have requirements on the placement of various
> kinds of entities. It subsumes those requirements under the
> term "alignment."
The _only_ important thing is to specify how programs should
be written. As you said, the standard needs to be implementation
neutral.
I think this has been completly lost in this thread.
Where does alignement comes to play in C/C++ programs is the key
question. I think that it's a requirement when an object is
new-ed:
new (p) T
p should be aligned for T.
Thus we need to know when a pointer p is sufficiently
aligned for a given type T:
- when returned by malloc
- when returned by operator new
- when stack allocated (in 'auto T x;' x is correctly aligned
for the type T)
In order to allocate storage manually, we need to know
about other cases:
- char arrays
- p + n (maybe strange the story about the division
comes to play here ?)
This is interresting iff we are doing low level tricks,
custom memory allocator, of things like that; and such
things are (should be) covered by the C/C++ standard.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]