Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!cornell!uw-beaver!mit-eddie!ll-xn!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Why should "sizeof" be unsigned? Message-ID: <22242@sun.uucp> Date: Sat, 27-Jun-87 03:13:10 EDT Article-I.D.: sun.22242 Posted: Sat Jun 27 03:13:10 1987 Date-Received: Sun, 28-Jun-87 01:03:43 EDT References: <1748@plus5.UUCP> <586@haddock.UUCP> <1750@plus5.UUCP> <1557@sfsup.UUCP> Sender: news@sun.uucp Lines: 42 > The fact is, a "length" of -1 is not just out of band data, it's data > that can't be held by the type of the sizeof operator. You're missing the point. The fact is, there are C compilers where the type of "sizeof" is "int", not "unsigned int", and thus -1 is NOT "data that can't be held by the type of the 'sizeof' operator". (See the document "The C Enviroment of UNIX/TS", supplied with the System III documentation. It states: 3.2.2 Unsigned numbers The value returned by "sizeof" is now "unsigned" rather than "int", so care must be exercised in the use of "sizeof" in a few strange cases. I seem to remember seeing this change mentioned elsewhere, but I don't remember where. I don't know when this change was made; was it made in V7 or afterwards? The odd thing is that the 4BSD C compiler is based on the System III VAX C compiler, but has "sizeof" yield an "int". I don't know if 1) the VAX C compiler hadn't been changed as of System III, 2) the change antedated V7, and Berkeley changed the compiler back to the V7 rules for backward compatiblity, or 3) something else happened. I seem to remember seeing *something* about such a change in or before V7, but I also seem not to remember noticing the type of "sizeof" differing between the System III and 4BSD C compiler.) The complaint being made is that having "sizeof" yield a value of type "unsigned int", rather than "int", precludes having -1 as an out-of-band value for routines that normally take a "sizeof". Saying "'sizeof' yields a value of type 'unsigned int', so you can't use -1 as an out-of-band value anyway" doesn't argue that the complaint is invalid, it just points out why the complaint is being made in the first place! (I have no strong opinion either way on this. I merely point out that "the type of 'sizeof' is 'unsigned int'" is not, by itself, a valid argument against the proposition that it should be "int".) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com