Packed Structures?

rbk at sequel.UUCP rbk at sequel.UUCP
Fri Sep 30 02:46:01 AEST 1983


Has anyone ever thought about the problems of exchanging binary
data-structures between two different machines/compilers?  (of course
you have!)  I had a thought about "packed" structures (borrowing an
idea from Pascal) that might help some of the problem:

	struct	garf	{
		char	g_char;
		short	g_int;
		char	g_char2;
		long	g_long;
	};

This has "holes" in it that will align differently on differnet machines
(eg, VAX vs PDP-11).  Suppose there was "packed struct", such as:

	packed struct garf g_var;

That insisted the structure have all possible holes squeezed out of it;
on a VAX, NS16k, 8086/286 all holes go away; on PDP-11 and 68K (I
think) you still have short/int requiring even alignment.  This should
be easy for compilers to implement, and doesn't cost the program
anything unless used.

The binary-data-structure problem is a tough one in general.  "Packed"
doesn't solve the problem completely (and doesn't address the byte-order
problem at all), but might help some.  Clearly if *you* get to specify the
structure (and you are careful) the problem is minimized without this;
however, there are many pre-existing data-structures out there that you
have to live with.

Comments?  Any other thoughts?  Flames >& /dev/null, please...
-- 
	Bob Beck
	Sequel Computer Systems
	...ogcvax!sequel!rbk
	(503)627-9809



More information about the Comp.lang.c mailing list