www.digitalmars.com         C & C++   DMDScript  

c++ - Compiler problem

reply Edward Diener <eddielee_no_spam_here tropicsoft.com> writes:
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
parent reply Walter Bright <newshound2 digitalmars.com> writes:
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.
Aug 28 2010
parent reply Edward Diener <eddielee_no_spam_here tropicsoft.com> writes:
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."
Aug 28 2010
parent reply Walter Bright <newshound2 digitalmars.com> writes:
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
parent reply Cesar Rabak <crabak acm.org> writes:
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.
Jan 12 2011
parent Walter Bright <newshound2 digitalmars.com> writes:
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.
Jan 12 2011