Thread View: gnu.g++.bug
3 messages
3 total messages
Started by Dirk Grunwald
Tue, 17 Oct 1989 18:41
sizeof(Class) vs. size passed to Class::new
Author: Dirk Grunwald
Date: Tue, 17 Oct 1989 18:41
Date: Tue, 17 Oct 1989 18:41
16 lines
1034 bytes
1034 bytes
If you define an overloaded new, you're passed the size of the structure you are to allocate. In the latest g++.xtar.Z, this differs from the value returned via ``sizeof'' for that class. Is this intentional? For example, in one class I have, operator new is passed a size of 183 while sizeof returns 176. Does the sizeof() operator omit space for vtable pointers? Why 7 bytes different? Is this a bug or a feature? Dirk Grunwald -- Univ. of Colorado at Boulder (grunwald@foobar.colorado.edu)
sizeof(Class) vs. size passed to Class::new
Author: Michael Tiemann
Date: Tue, 17 Oct 1989 22:05
Date: Tue, 17 Oct 1989 22:05
33 lines
1823 bytes
1823 bytes
Date: Tue, 17 Oct 89 12:41:35 -0600 From: grunwald@foobar.colorado.edu (Dirk Grunwald) Reply-To: grunwald@foobar.colorado.edu Office: 6-1 EECR (303) 492-0452 If you define an overloaded new, you're passed the size of the structure you are to allocate. In the latest g++.xtar.Z, this differs from the value returned via ``sizeof'' for that class. Is this intentional? For example, in one class I have, operator new is passed a size of 183 while sizeof returns 176. Does the sizeof() operator omit space for vtable pointers? Why 7 bytes different? Is this a bug or a feature? Dirk Grunwald -- Univ. of Colorado at Boulder (grunwald@foobar.colorado.edu) Your class has an object which requires 8 byte alignment. Since malloc does not, a priori, give you reasonably aligned memory, I make the compiler ask for enough that it can cause that memory to be appropriately aligned. The way I implement this assumes a minimum alignment from malloc. Conservatively this would be 1 byte, but it would be inefficient to force alignment of every call to malloc, so I assume malloc returns chunks which are aligned enough for a pointer. In most cases, this is four bytes. Michael
Re: sizeof(Class) vs. size passed to Class::new
Author: Andrew Klossner
Date: Wed, 18 Oct 1989 17:37
Date: Wed, 18 Oct 1989 17:37
12 lines
1022 bytes
1022 bytes
Michael writes:
"Since malloc does not, a priori, give you reasonably aligned
memory ..."
On what system does malloc misbehave in this way? The BSD, system V,
and SunOS man pages all state that malloc *does* give correctly aligned
memory, and I haven't yet encountered an implementation for which this
is untrue. (Maybe you have a non-Unix system in mind?)
-=- Andrew Klossner (uunet!tektronix!frip.WV.TEK!andrew) [UUCP]
(andrew%frip.wv.tek.com@relay.cs.net) [ARPA]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads