Structure Member Padding

Peter da Silva peter at ficc.ferranti.com
Wed Jul 11 01:35:33 AEST 1990


In article <10420 at ogicse.ogc.edu> daniels at ogicse.ogc.edu (Scott David Daniels) writes:
> 	struct first { char a; short s; };
> 	struct second{ char a; short s; char b; };
> 	struct third { char a; char b; short s; };
> I would like to be able to use the same layout for third and second, ...

struct head { char a; short b; };
struct first { char a; short b; long c; };
struct second { char a; short b; char c; };

You want to shove second.c between second.a and second.b, right?

copyhead(dest, src)
struct head *dest, *src;
{
	*dest = *src;
}

	struct first a;
	struct second b;

	copyhead(b, a);

You just clobbered b.c if you do that.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.
<peter at ficc.ferranti.com>



More information about the Comp.std.c mailing list