Packed structures (was: Absolute size of 'short')

Peter da Silva peter at ficc.UUCP
Tue Aug 16 01:52:56 AEST 1988


In article <6104 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
> In article ... davidsen at crdos1.UUCP (bill davidsen) writes:
> >I would really like to see a "packed struct," also. This would be a
> >struct packed on byte boundaries without fill, no matter *how bad* the
> >code was to use them.

> Consider the following code:
> 	packed struct { char c; int i; } x;
> 	int *p = &x.i;
        ^^^^^^^^^^^^^ This should be illegal.
> 	*p = 0;

It is already illegal to take the address of one object with no legal
address... a register variable. Why should it be legal to take the address
of a misaligned integer?

Another comment: what about:

	packed struct { int a:1; int b; int c:17; } argh;
-- 
Peter da Silva, Ferranti International Controls Corporation, sugar!ficc!peter.
"You made a TIME MACHINE out of a VOLKSWAGEN BEETLE?"
"Well, I couldn't afford another deLorean."
"But how do you ever get it up to 88 miles per hour????"



More information about the Comp.lang.c mailing list