Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 27, 2010 Compiler problem | ||||
---|---|---|---|---|
| ||||
The code: #include <wchar.h> #include <limits.h> #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) #endif as TestFile.cpp when compiled gives: #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) ^ TestFile.cpp(3) : Error: ')' expected #endif ^ TestFile.cpp(4) : Preprocessor error: '#endif' found without '#if' --- errorlevel 1 |
August 29, 2010 Re: Compiler problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Edward Diener wrote: > The code: > > #include <wchar.h> > #include <limits.h> > #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) > #endif > > as TestFile.cpp when compiled gives: > > #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) > ^ > TestFile.cpp(3) : Error: ')' expected This is because WCHAR_MAX is defined as: (wchar_t)0xFFFF and casts are not allowed in preprocessor expressions. You can tell this by compiling this way: H:ztc>dmc -c test -e -l #if defined(WCHAR_MAX) && ((wchar_t)0xFFFF ^ test.cpp(3) : Error: ')' expected Using -e -l will show the line after macro expansion. |
August 29, 2010 Re: Compiler problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 8/28/2010 8:40 PM, Walter Bright wrote: > Edward Diener wrote: >> The code: >> >> #include <wchar.h> >> #include <limits.h> >> #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) >> #endif >> >> as TestFile.cpp when compiled gives: >> >> #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX) >> ^ >> TestFile.cpp(3) : Error: ')' expected > > > This is because WCHAR_MAX is defined as: > > (wchar_t)0xFFFF > > and casts are not allowed in preprocessor expressions. > > You can tell this by compiling this way: > > H:ztc>dmc -c test -e -l > #if defined(WCHAR_MAX) && ((wchar_t)0xFFFF > ^ > test.cpp(3) : Error: ')' expected > > Using -e -l will show the line after macro expansion. I believe it is therefore clearly misdefined, as it is supposed to be a constant expression that one can use in preprocessor #if expressions. In the Ansi C standard we have in 7.18.3 "Limits of other integer types" in paragraph 2: "Each instance of these macros shall be replaced by a constant expression suitable for use in #if preprocessing directives, and this expression shall have the same type as would an expression that is an object of the corresponding type converted according to the integer promotions." |
August 29, 2010 Re: Compiler problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Edward Diener wrote:
> "Each instance of these macros shall be replaced by a constant expression suitable for use
> in #if preprocessing directives, and this expression shall have the same type as would an
> expression that is an object of the corresponding type converted according to the integer
> promotions."
You're right. I took off the (wchar_t) casts in \dm\include\wchar.h and \dm\include\stdint.h.
|
January 12, 2011 Re: Compiler problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Em 29/8/2010 01:54, Walter Bright escreveu:
> Edward Diener wrote:
>> "Each instance of these macros shall be replaced by a constant
>> expression suitable for use
>> in #if preprocessing directives, and this expression shall have the
>> same type as would an
>> expression that is an object of the corresponding type converted
>> according to the integer
>> promotions."
>
> You're right. I took off the (wchar_t) casts in \dm\include\wchar.h and
> \dm\include\stdint.h.
Were those changes reflected in any patch/update? v852 seems to be the last update available. However, checking the mentioned header files don't show any modifications.
|
January 12, 2011 Re: Compiler problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cesar Rabak | Cesar Rabak wrote:
> Em 29/8/2010 01:54, Walter Bright escreveu:
>> Edward Diener wrote:
>>> "Each instance of these macros shall be replaced by a constant
>>> expression suitable for use
>>> in #if preprocessing directives, and this expression shall have the
>>> same type as would an
>>> expression that is an object of the corresponding type converted
>>> according to the integer
>>> promotions."
>>
>> You're right. I took off the (wchar_t) casts in \dm\include\wchar.h and
>> \dm\include\stdint.h.
>
> Were those changes reflected in any patch/update? v852 seems to be the last update available. However, checking the mentioned header files don't show any modifications.
No, but I'll email them to you.
|
Copyright © 1999-2021 by the D Language Foundation