🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3294

C structs in heterogenous environments

#3294
From: Marko Asplund
Date: Tue, 29 Sep 1998 00:00
26 lines
1619 bytes
i have an application where i need to send C structs, with BSD socket
interface's read() and write() routines, between heterogenous machine
architectures. the structs are quite simple containing only char arrays
and integers e.g.

	struct data {
		char somestring[9];
		int status;
		int foo;
		char otherstring[5];
	};


so, my question is how do i accomplish sending this struct over the
network, to a machine with different architecture? when i do a write()
does the system send everything in the struct, including padding fields,
over the network? i assume i can rely on the C compiler to preserve the
order of the struct members. but, i probably can't rely on int member
fields being of certain length (at least not on all platforms). can i
assume something about the paddings between members? for example, can i
assume that if the char arrays lengths are multiples of 4, there will be
no padding fields in most architecture?


--
	aspa
Technical Details
Message-ID: <3610F74A.A7A6BECD@mail.cern.ch>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc89c,e19b5afbbfd1f181,start
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 1132ff,e19b5afbbfd1f181,start
X-Google-Attributes: gid1132ff,public
From: Marko Asplund <aspa@mail.cern.ch>
Subject: C structs in heterogenous environments
Date: 1998/09/29
Message-ID: <3610F74A.A7A6BECD@mail.cern.ch>
X-Deja-AN: 396010723
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@sunnews.cern.ch
X-Trace: sunnews.cern.ch 907081766 12223 (None) 137.138.98.87
Organization: HIP
Mime-Version: 1.0
Newsgroups: comp.unix.programmer,cern.unix