Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!tymix!cirrusl!sunstorm!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: sizeof() confusion Message-ID: <2692@cirrusl.UUCP> Date: 13 Nov 90 21:26:57 GMT References: <9156@latcs1.oz.au> <27432@mimsy.umd.edu> <2665@cirrusl.UUCP> <1990Nov10.123204.8968@druid.uucp> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 23 >> printf("sizeof c = %d\n", sizeof c); >> printf("sizeof 'c' = %d\n", sizeof 'c'); >Were you suprised that "'c'" was 4? >You shouldn't be. That expression evaluates to an int, not a char. 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. 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. 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. -- Rahul Dhesi UUCP: oliveb!cirrusl!dhesi