Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsj!asd From: asd@cbnewsj.att.com (Adam S. Denton) Newsgroups: comp.lang.c Subject: Re: sizeof() confusion Message-ID: <1990Nov14.154213.27324@cbnewsj.att.com> Date: 14 Nov 90 15:42:13 GMT References: <9156@latcs1.oz.au> <27432@mimsy.umd.edu> <2665@cirrusl.UUCP> <2692@cirrusl.UUCP> Organization: AT&T Bell Laboratories, Middletown, NJ Lines: 35 In article <2692@cirrusl.UUCP>, dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) writes: > If characters are promoted to ints in expressions, then why isn't > |sizeof c| equivalent to |sizeof (int) c|? The confusion arises > because the term "expression" is defined differently in the definition > of C and in colloquoal conversation. You take sizeof() of an object, not an expression. > From my point of view -- call it naive if you will -- anything > that has a value is an "expression". Therefore, if |c| as used above > has a value, it's an expression. Therefore |c| must be promoted to > int. Therefore |sizeof c| is equivalent to |sizeof (int) c|. Hence > the surprise. Your view is nice, but is not C. > I'm sure K&R, H&S, and the ANSI standard all define these things in > various places. But they can only guarantee what things mean, not > whether the meanings they define will surprise programmers. It is the responsibility of the programmer to know the language and use it properly, whether the language is perfect or not. A hammer works quite well driving nails. It's not the hammer's fault if I have difficulty drilling holes with it. C works quite well with sizeof() and promotions defined the way they are. Perhaps they could be better, but widely-available C compilers do them the current way -- for good or ill. If I want to avoid writing my own compiler and my own non-portable code, I had better code using what's out there and accepted NOW. So (IMHO) no one should EVER be "surprised" at C. If they are, then they haven't read and/or understood the manual or the Standard or whatever applies. To use a tool properly, you must know how to do so. C is a tool. Adam Denton asd@mtqua.att.com