Re: Compile Error C1017 With sizeof()



On Wed, 10 May 2006 00:54:46 -0400, "Alexander J. Oss" <alex@xxxxxxxxxxx>
wrote:

Visual Studio 2005 Standard is giving me "fatal error C1017: invalid integer
constant expression" on code that compiles fine in Borland land:

#if sizeof(char)==1

The standard says:

(5.19.1) ...An integral constant-expression can involve only ... and sizeof
expressions.

and

(5.3.3.1) sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1

That last quote from the standard makes it clear that my code is pretty
useless, since by the standard I'll never have any other case. However,
this shouldn't cause a compilation error, should it?

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.

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... "An arithmetic constant expression shall satisfy the requirements for ... Comeau, however, compiles this program too, so I am ... whether, after studying the Standard, I think it is conformant code. ... we diagnose it for you and protect ...
    (microsoft.public.vc.language)
  • Compile Error C1017 With sizeof()
    ... constant expression" on code that compiles fine in Borland land: ... sizeof(char), sizeofand sizeofare 1 ... That last quote from the standard makes it clear that my code is pretty ...
    (microsoft.public.vc.language)
  • Re: Destructor: not gauranteed to be called?
    ... >>> the ToStringmethod to a Char[] it returns with the EXACT SAME ... >>> the standard and might break someone's existing code. ... ToString is not part of the C++ ... The fact yhat you require or expect a Charto act as a string is a sign ...
    (microsoft.public.dotnet.languages.vc)
  • Re: byte order
    ... int am_i_little_endian{ ... Are you *absolutely* sure that's standard C, ... assuming a 8-bit char). ... The pointer casting rules specify that "It is guaranteed that ...
    (comp.lang.lisp)
  • Re: An Observation
    ... You execute it now or you execute it later. ... I explained CHAR and as I did in my prior post in ... complexity around and was not actually any simpler. ... because of the sloppiness of the standard. ...
    (comp.lang.forth)

Loading