Path: utzoo!utgpu!water!watmath!clyde!skep2!wcs From: wcs@skep2.ATT.COM (Bill.Stewart.[ho95c]) Newsgroups: comp.lang.c Subject: Re: Portability of passing/operating on structures... Message-ID: <289@skep2.ATT.COM> Date: 19 Oct 88 02:26:33 GMT References: <8810111934.AA21941@ucbarpa.Berkeley.EDU> Reply-To: wcs@skep2.UUCP (46323-Bill.Stewart.[ho95c],2G218,x0705,) Organization: AT&T Bell Labs Center 4632, Holmdel, NJ Lines: 29 In article <8810111934.AA21941@ucbarpa.Berkeley.EDU> U23405@UICVM.Berkeley.EDU (Michael J. Steiner) writes: > Is it considered portable to do the following things with > structures or unions? There were a number of additions to the C language in about 1980, after the original K&R book, which almost everyone has adopted, even most compilers that call themselves "K&R". The main features were void, enums, and structure handling. Not everybody has them, but the following things are portable to any useful environment. > -pass them (by value) to functions Yes. > -have functions which return them Yes. Note that the mechanism for returning the value is implementation-defined. Some people put them on the stack; others may do arbitrarily strange things. > -assign them (=) Yes. > -test them (structures only) for equality with == No! The problem is that structures typically have holes in them caused by alignment requirements, and these holes have arbitrary junk in them. When you assign one structure to another, this junk is generally copied, but if you assign values member by member you aren't changing the junk in the holes, so equality comparisons don't work. -- #Bill Stewart, AT&T Bell Labs 2G218 Holmdel NJ 201-949-0705 ho95c.att.com!wcs # New Jersey Division of Motor Vehicles - # rising to a new level of incompetence