Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: iso646.h Date: Thu, 25 Jan 2024 07:26:05 -0800 Organization: None to speak of Lines: 60 Message-ID: <87ttn14epe.fsf@nosuchdomain.example.com> References: <87r0i65w9u.fsf@nosuchdomain.example.com> <8734um5ai7.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="25cdfcf079fd064704ce92ded0c098b3"; logging-data="2476979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dWF8Jr4w99lqC3audr+x2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:LeVZYCsiP8GXVST4Zn1sRSbRCzc= sha1:QuQbgAW94xYwZiKiSko9Qy4al38= Xref: csiph.com comp.lang.c:380915 David Brown writes: > On 25/01/2024 10:55, Malcolm McLean wrote: >> On 25/01/2024 03:59, Keith Thompson wrote: > >>> As for K&R's thinking, I have no particular insight on that.  I have no >>> problem with some operators being represented by symbols and others by >>> keywords (I'm accustomed to it from other languages), and I don't see >>> that the decision to make "sizeof" a keyword even requires any >>> justification. >>> >> I looked it up on the web, but I can't find anything that goes back >> to K and R and explains why they took that decision. But clearly to >> use a word rather than punctuators, as was the case with every other >> operator, must have had a reason. > >> I think they wanted it to look function-like, because it is >> function, though a function of a type rather than of bits, so of >> course not a "function" in the C standard sense of the term. > > It is not a function in the C sense - "sizeof x" is not like a > function call (where "x" is a variable or expression, rather than a > type). However, many people (myself included) feel it is clearer in > code to write it as "sizeof(x)", making it look more like a function > or function-like macro. And many people (myself included) feel it is clearer to write it as `sizeof x`, precisely so it *doesn't* look like a function call, because it isn't one. Similarly, I don't use unnecessary parentheses on return statements. I also write `sizeof (int)` rather than `sizeof(int)`. The parentheses look similar to those in a function call, but the construct is semantically distinct. I think of keywords as a different kind of token than identifiers, even though they look similar (and the standard describes them that way). > I suspect the prime reason "sizeof" is a word, rather than a symbol or > sequence of symbols, is that the word is very clear while there are no > suitable choices of symbols for the task. The nearest might have been > "#", but that might have made pre-processor implementations more > difficult. Of course any symbol or combination /could/ have been > used, and people would have learned its meaning, but "sizeof" just > seems so much simpler. It has occurred to me that if there had been a strong desire to use a symbol, "$" could have worked. It even suggests the 's' in the word "size". But there was no such desire. sizeof happens to be the only operator whose symbol is a keyword, but I see no particular significance to this, and no reason not to define it that way. I might even have preferred keywords for some of C's well-populated zoo of operators. See also Pascal, which has keywords "and", "or", "not", and "mod". [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */