Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site sequel.UUCP Path: utzoo!linus!decvax!tektronix!ogcvax!sequel!rbk From: rbk@sequel.UUCP Newsgroups: net.lang.c,net.unix.wizards Subject: Packed Structures? Message-ID: <274@sequel.UUCP> Date: Thu, 29-Sep-83 12:46:01 EDT Article-I.D.: sequel.274 Posted: Thu Sep 29 12:46:01 1983 Date-Received: Sun, 2-Oct-83 18:37:13 EDT Organization: Sequel Computer Systems, Portland Lines: 36 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