Topic: The enormous-struct-hack (was: struct hack idea)
Author: swf@ElSegundoCA.NCR.COM (Stan Friesen)
Date: Mon, 15 Aug 94 10:01:45 PDT Raw View
In article <rfgCuJxs8.J60@netcom.com>, rfg@netcom.com (Ronald F. Guilmette) writes:
|>
|> Consider the following case:
|>
|> struct { char a[5]; } a[10];
|>
|> The question is: `What is the sizeof(a)?'
|> ...
|> Implied by the statements I made in my earlier posting is the implicit
|> assertion that I know of no compilers for which sizeof(a) would NOT
|> be equal to 50 (or perhaps 50 rounded up to some word size boundary).
|>
|> Are you saying that you have a compiler where sizeof(a) == 80??
|>
Hmm, I am not sure, but I think on a Sparc it would be either 60 or 80.
(At least I do not think Sparc compilers make byte aligned struct's).
--
swf@elsegundoca.ncr.com sarima@netcom.com
The peace of God be with you.
Author: mec@shell.portal.com (Michael Edward Chastain)
Date: 15 Aug 1994 19:10:12 GMT Raw View
In article <9408151701.AA14372@tdat.elsegundoca.ncr.com>,
Stan Friesen <swf@ElSegundoCA.NCR.COM> wrote:
> Hmm, I am not sure, but I think on a Sparc it would be either 60 or 80.
> (At least I do not think Sparc compilers make byte aligned struct's).
It's 50 bytes long on my Sparc with the bundled '/bin/cc' and with
the Gnu 2.5.8 compiler.
Here is my test program.
struct { char a[5]; } a[10];
int i = sizeof(a);
I compiled to assembler and read the generated code.
SunOS 4.1.3, sun4m, '/bin/cc -S': 'i' is initialized to 0x32.
SunOS 4.1.3, sun4m, 'gcc -S', gcc version 2.5.8.: 'i' initialized
to 50 decimal.
SunOS 4.1.3, sun4m, 'g++ -S', g++ version 2.5.8: 'i' initialized
to 50 decimal.
Michael Chastain
mec@shell.portal.com
Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Tue, 16 Aug 1994 09:15:01 GMT Raw View
In article <9408151701.AA14372@tdat.ElSegundoCA.NCR.COM> swf@ElSegundoCA.NCR.COM writes:
>In article <rfgCuJxs8.J60@netcom.com>, rfg@netcom.com (Ronald F. Guilmette) writes:
>|>
>|> Consider the following case:
>|>
>|> struct { char m[5]; } a[10];
>|>
>|> The question is: `What is the sizeof(a)?'
>|> ...
>|> Implied by the statements I made in my earlier posting is the implicit
>|> assertion that I know of no compilers for which sizeof(a) would NOT
>|> be equal to 50 (or perhaps 50 rounded up to some word size boundary).
>|>
>|> Are you saying that you have a compiler where sizeof(a) == 80??
>|>
>Hmm, I am not sure, but I think on a Sparc it would be either 60 or 80.
>(At least I do not think Sparc compilers make byte aligned struct's).
First, let me say that I'm unsure how this follow-up managed to leak
over here into comp.std.c++. (I could have sworn that I posted this
item over in comp.std.c ONLY.)
Second, let me just mention that as far as sparc compilers are concerned,
your supposition is incorrect. I tried five such compilers myself (all
different... not just different revs of the same compiler) and they all
agreed that the sizeof(a) == 50.
(By the way, four popular DOS-hosted 16-bit x86 compilers also agreed
that sizeof(a) == 50, as did DEC's C compiler on the 64-bit Alpha.)
In comp.std.c, I suggested that the folks who wrote the C standard missed
something (which would have helped portability) when they failed to include
(in the C standard) such simple stipulations as ``The alignment of a struct
or union type shall be equal to the least common multiple of the alignments
of all of the members contained therein.''
As long as this issue has spilled over here (into comp.std.c++) I should
say that my sentiments also apply equally to the C++ standard which is
still in progress. I hope that the final C++ standard will contain exactly
such a rule.
--
-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -