Re: Compile Error C1017 With sizeof()



Alexander J. Oss wrote:
It should, since sizeof isn't part of the preprocessor
language. And you're
right, sizeof(char) is 1 by definition. In C and C++
terms, "char" and "byte" are synonymous, and they don't
necessarily imply 8 bits, though usually they do.

The preprocessor language includes "constant-expression"
(according to 16.1.1 and 16.1.3), and 5.19 is what defines
an integral
"constant-expression", and that definition includes
sizeof().
...ugh, I just found the following quote at
http://msdn2.microsoft.com/en-us/library/ew2hz0yd.aspx:

The expression cannot use sizeof or a type-cast operator.

Why is this quote present here but not in the C++
standard (that I could find)?

Because C++ Standard is terse document, which provides
shortest (most of the time) definitions of language
concepts. MSDN is broader and includes commentaries and
interpretations. Once it's in preprocessor section of the
Standard the assumption is that compiler stuff is excluded.
MSDN explicitly states this fact and enumerates limitations
for preprocessor constant expression.

`sizeof' is compile time operator, i.e. it's evaluated by
compiler. Preprocessor runs before compilation, hence
`sizeof' is unknown during this stage.


.



Relevant Pages

  • Re: Is C99 the final C? (some suggestions)
    ... > that someone will try compile their stuff on an old compiler. ... > because the ANSI standard obsoleted them, and everyone picked up the ANSI ... fixed by using another language. ... >>are multiplying two expressions of the widest type supported by your ...
    (comp.lang.c)
  • Re: Forth Frustrations
    ... How would they even know what they are without being language lawyers? ... standard systems and a large number of nonstandard ones. ... interpreter, ... They set up four states -- HOST INTERPRETER COMPILER ...
    (comp.lang.forth)
  • Re: Forth Frustrations
    ... How would they even know what they are without being language lawyers? ... Then if you choose a standard system you can write code for it, ... interpreter, ... They set up four states -- HOST INTERPRETER COMPILER ...
    (comp.lang.forth)
  • Re: Is C99 the final C? (some suggestions)
    ... This would violate the division between preprocessor and compiler too ... much (the preprocessor would have to understand quite a lot of C semantics). ... ...This is legal C (as per the Standard), but it overflows the stack on ...
    (comp.lang.c)
  • Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... > the standard language. ... Or did they just implemented some 80% of the new features? ... there was a fully compiant C compiler available. ...
    (comp.lang.ada)