Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!bbn.com!nic!kira!emily!wollman From: wollman@emily.uvm.edu (Garrett Wollman) Newsgroups: comp.lang.c Subject: Re: why do structs have different sizes across machines? Message-ID: <1991Mar30.021653.6492@uvm.edu> Date: 30 Mar 91 02:16:53 GMT References: <77336@bu.edu.bu.edu> <1991Mar26.065356.577@thunder.mcrcim.mcgill.edu> Sender: news@uvm.edu Distribution: na Organization: University of Vermont - EMBA Computing Facility Lines: 31 Raymond-Protection: enabled In article <1991Mar26.065356.577@thunder.mcrcim.mcgill.edu> mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes: >In article <77336@bu.edu.bu.edu>, jdubb@bucsf.bu.edu (jay dubb) writes: >> Can anyone explain to me why the following short program give the >> size of the structure as 38 on a Sun 3, and 40 on an Encore Multimax: > >The other choice is to put the structure in some portable form for >transmission over the connection. This could mean anything from >judicious use of ntohl() and related routines to converting everything >to text. This slows you down, of course, but in the vast majority of >the cases the gain in portability and maintainability is worth it. If one is really intent on sending binary structures across sockets (presumes 4BSD IPC, so "portability" is already somewhat compromised), there is a simple solution to the problem. Both the Multimax (this machine, at any rate) and the Sun-X (for appropriate values of X>=3) support Sun's XDR, which basically allows you to feed your structure definition to a compiler, which will create routines to portably convert the structure into something suitable for sending across a network, and then convert it back at the other end. [In this day and age, it's a fair assumption that Most Networked Unix Systems Which Are Derived From 4BSD Support NFS, and NFS presupposes XDR.] -GAWollman PS: For that matter, our SVR3 SGI machines support NFS, too... Garrett A. Wollman - wollman@emily.uvm.edu Disclaimer: I'm not even sure this represents *my* opinion, never mind UVM's, EMBA's, EMBA-CF's, or indeed anyone else's.