chris@mimsy.UUCP (Chris Torek) (07/26/88)
>henry@utzoo.uucp (Henry Spencer) writes: >|You have an out-of-date draft, I believe. The second-public-comment draft >|(I haven't seen the third yet) explicitly forbids sizeof in this context. In article <11637@steinmetz.ge.com> davidsen@steinmetz.ge.com (William E. Davidsen Jr) answers: > I believe what I have is current. I got it a week ago and it's marked >as THIRD public review. The many references were all based on that draft. That should be the May 13, 1988 draft. See footnote 74 on page 84. While the explicit wording against sizeof is gone (yet the explicit prohibition of casts remains), the footnote remarks that the expression is evaluated in translation phase 4, where keywords do not yet exist. Hence the token `sizeof' is either defined (via #define) as some other token, or is simply an identifier token: it cannot be used to find the size of an object. (Likewise, all types do not yet exist as keywords, hence casts are implicitly impossible, although this is less obvious.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
bill@proxftl.UUCP (T. William Wells) (07/26/88)
In article <12674@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
: That should be the May 13, 1988 draft. See footnote 74 on page 84.
: While the explicit wording against sizeof is gone (yet the explicit
: prohibition of casts remains), the footnote remarks that the expression
: is evaluated in translation phase 4, where keywords do not yet exist.
: Hence the token `sizeof' is either defined (via #define) as some other
: token, or is simply an identifier token: it cannot be used to find the
: size of an object. (Likewise, all types do not yet exist as keywords,
: hence casts are implicitly impossible, although this is less obvious.)
The committee has made it clear that the preprocessor should be
able to be written independently of the execution environment.
This is the rationale behind a number of disquieting things
(e.g., character constants not having to be the same to the
preprocessor and in the execution environment). From that
standpoint, the preprocessor could not be aware of sizeof as that
would be dependent on the execution environment.
davidsen@steinmetz.ge.com (William E. Davidsen Jr) (07/26/88)
In article <12674@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: | That should be the May 13, 1988 draft. See footnote 74 on page 84. | While the explicit wording against sizeof is gone (yet the explicit | prohibition of casts remains), the footnote remarks that the expression | is evaluated in translation phase 4, where keywords do not yet exist. | Hence the token `sizeof' is either defined (via #define) as some other | token, or is simply an identifier token: it cannot be used to find the | size of an object. (Likewise, all types do not yet exist as keywords, | hence casts are implicitly impossible, although this is less obvious.) I guess some wording better be put back in fn74, since everywhere I could find in the standard (including the index) sizeof is refered to as an *operator* rather than a keyword or statement. As such I would expect that it would function as well in #if as do +, -, etc. Perhaps this should be clarified again, as it was in the 2nd draft. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me
chris@mimsy.UUCP (Chris Torek) (07/27/88)
>In article <12674@mimsy.UUCP> I wrote [a comment about sizeof being a keyword, and that footnote 74 points out that keywords do not yet exist]. In article <11654@steinmetz.ge.com> davidsen@steinmetz.ge.com (William E. Davidsen Jr) writes: > I guess some wording better be put back in fn74, since everywhere I >could find in the standard (including the index) sizeof is refered to as >an *operator* rather than a keyword or statement. It is indeed an operator. `operator' and `keyword' are not mutually exclusive (although, as it happens, this is the only C keyword that is also an operator). (In Pascal, e.g., the keywords `div' and `mod' are operators.) >As such I would expect that it would function as well in #if as do +, >-, etc. Perhaps this should be clarified again, as it was in the 2nd draft. I agree with the latter sentiment, although I see this as a relatively minor issue. (There are things that the draft seems to say that I find even less obvious than this---e.g., Arthur Olson's observations on reserved names.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
jfh@rpp386.UUCP (John F. Haugh II) (07/28/88)
In article <12685@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: |>In article <12674@mimsy.UUCP> Chris wrote [a comment about sizeof being a | keyword, and that footnote 74 points out that keywords do not yet exist]. [ and chris then further agrees that sizeof is not a keyword, but an operator instead ] | |>As such I would expect that it would function as well in #if as do +, |>-, etc. Perhaps this should be clarified again, as it was in the 2nd draft. | |I agree with the latter sentiment, although I see this as a relatively |minor issue. (There are things that the draft seems to say that I find |even less obvious than this---e.g., Arthur Olson's observations on reserved |names.) sizeof has nothing to operate on. there is no means of specifying the datatype or variable whose size is to be determined. - john. -- John F. Haugh II +--------- Cute Chocolate Quote --------- HASA, "S" Division | "USENET should not be confused with UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE" DOMAIN: jfh@rpp386.uucp | -- with my apologizes
blandy@marduk.cs.cornell.edu (Jim Blandy) (07/28/88)
In article <4543@rpp386.UUCP> jfh@rpp386.UUCP (The Beach Bum) writes: >sizeof has nothing to operate on. there is no means of specifying the >datatype or variable whose size is to be determined. Absolutely right. Expressions in #ifs are evaluated by the C preprocessor (obviously), which doesn't know anything about variables or their types. Remember that cpp is often implemented as a separate program, with no access to the information the compiler maintains about a variable's type, etc. In order to get it to do sizeof, cpp would have to parse declarations out of the source code it was preprocessing and store them in its own symbol table - a big duplication of effort, and a disaster for other programs that use CPP on non-C text (like Cornell's Synthesizer Generator). An alternative to consider: it's a simple task for a compiler to recognize that the condition for an if ( ) statement is a constant, use this knowledge in guessing which statements are unreachable, and drop unreachable code. For example, I wouldn't be surprised if a good compiler would take if (sizeof(a_structure) > THELARGESTIWANTTOTHINKABOUT) ... action for big structures ... else ... action for small structures ... , recognize that the condition is constant, and code only the appropriate branch. This may provide the capability you want. -- Jim Blandy - blandy@crnlcs.bitnet "And now," cried Max, "let the wild rumpus start!"
chris@mimsy.UUCP (Chris Torek) (07/28/88)
In article <4543@rpp386.UUCP> jfh@rpp386.UUCP (John F. Haugh II) writes: >In article <12685@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >[ and chris then further agrees that sizeof is not a keyword, but an > operator instead ] I did not say that. I said that sizeof is both a keyword *and* an operator. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
inb@creare.UUCP (Ian Brown) (07/29/88)
In article <19730@cornell.UUCP> blandy@cs.cornell.edu (Jim Blandy) writes: >Jim Blandy - blandy@crnlcs.bitnet >"And now," cried Max, "let the wild rumpus start!" A quote from a great childrens book (one of my favorites as a young child - also one of my mother's favorites for reading to children). -- =============================================================================== Ian Brown ..!dartvax!creare!inb
jfh@rpp386.UUCP (John F. Haugh II) (07/30/88)
In article <12713@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <4543@rpp386.UUCP> jfh@rpp386.UUCP (John F. Haugh II) writes: >>In article <12685@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>[ and chris then further agrees that sizeof is not a keyword, but an >> operator instead ] > >I did not say that. I said that sizeof is both a keyword *and* an >operator. my apologizes, that should have read [ and chris then further agrees that sizeof is not only a keyword, but also an operator ] my statement about CPP not being about to perform the sizeof() operation still stands. data types do not exist at that phase of the translation, and hence, neither do data type or variable sizes. -- John F. Haugh II +--------- Cute Chocolate Quote --------- HASA, "S" Division | "USENET should not be confused with UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE" DOMAIN: jfh@rpp386.uucp | -- with my apologizes