c++ - Compiler problem
- Edward Diener (13/13) Aug 27 2010 The code:
- Walter Bright (10/22) Aug 28 2010 This is because WCHAR_MAX is defined as:
- Edward Diener (12/34) Aug 28 2010 I believe it is therefore clearly misdefined, as it is supposed to be a
- Walter Bright (3/10) Aug 28 2010 You're right. I took off the (wchar_t) casts in \dm\include\wchar.h and
- Cesar Rabak (4/14) Jan 12 2011 Were those changes reflected in any patch/update? v852 seems to be the
- Walter Bright (2/18) Jan 12 2011 No, but I'll email them to you.
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
Aug 27 2010
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: ')' expectedThis 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.
Aug 28 2010
On 8/28/2010 8:40 PM, Walter Bright wrote:Edward Diener wrote: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."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: ')' expectedThis 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.
Aug 28 2010
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.
Aug 28 2010
Em 29/8/2010 01:54, Walter Bright escreveu:Edward Diener wrote: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."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.
Jan 12 2011
Cesar Rabak wrote:Em 29/8/2010 01:54, Walter Bright escreveu:No, but I'll email them to you.Edward Diener wrote: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."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.
Jan 12 2011