Path: utzoo!mnetor!uunet!husc6!rutgers!rochester!cornell!batcomputer!pyramid!prls!mips!hitz From: hitz@mips.UUCP (David Hitz) Newsgroups: comp.unix.questions Subject: Re: Portability Question Message-ID: <1178@quacky.UUCP> Date: 18 Dec 87 19:14:19 GMT References: <122@insyte.uucp> <9803@mimsy.UUCP> Reply-To: hitz@quacky.UUCP (David Hitz) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 47 Keywords: Portable VAX VMS vs HPUX c Summary: Does the standard specify integer representation? In article <9803@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: ] In article <122@insyte.uucp> jad@insyte.uucp (Jill Diewald) writes: ] ] ... HPUX c ... [and] VMS c ... [give] different answers. We want to ] ] know which is right (if either) so we can report it as a bug to the ] ] correct source. ] ... ] ] main() { ] ] struct { int x : 1; } foo; ] ] ] ] foo.x = 1; ] ] printf ("%d\n", foo.x); ] ] } ] ] Whether bitfields are signed is undefined. I believe the current ] draft says that to get a particular behaviour, you must use either ] of the `signed' or `unsigned' keywords. In other words, the code ] is wrong, not either of the compilers. Now I'm curious. Does ANSII require a hardware implementation to use 2s complement arithmetic for its integer representation? (Am I allowed to build a grey code machine?) If the standard doesn't say, then setting a single bit in a bitfield could result in an arbitrary integer. In K&R, the sections on bit fields and bit manipulation operators don't specify a particular representation. However, some examples do assume the following defines each map inidividual bits: #define FIELD1 1 #define FIELD2 2 #define FIELD3 4 which isn't true in an arbitrarary representation. And in the section on unsigned chars they do talk about sign extension which seems to imply 2s complement arithmetic. Some other C constructs are affected as well. For example, does the standard guarantee that ( (X << 1) == (X * 2))? Clearly there is too much code that relies on these features for them to change. I was just wondering if the standard is explicit. hitz -- Dave Hitz UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!hitz DDD: hitz@408-991-0345