Re: Win32 Build Issues

Subject: Re: Win32 Build Issues
From: David Mandelin (
Date: Tue Aug 07 2001 - 12:47:55 CDT

David Given wrote:
> [...]
> > MSVC gives the loop var i the scope of the outer block instead of the
> > for loop, so it gives an error for i being multiply defined.
> MSVC's behaviour is incorrect. The current standard decrees that any variables
> declared in a for() statement only have scope inside the loop --- but it used
> not to be the case. (gcc has an option, -fno-for-scope, to change the scoping
> rules when compiling old code.)
> > To fix this, we could (a) rename one of the vars, (b) remove one of the
> > definitions, or (c) turn off MS language extensions in the compiler (/Za
> > option). Doing 'c' causes problems in some other file, because MSVC
> > won't cast an enumeration value to a (void *) unless MS extensions are
> > on. I couldn't fine a way to selectively enable exensions. Whaddya want?
> Casting enums to a void*? Eeek! Don't do this! It's illegal! C++ won't let you
> cast *anything* to a pointer implicitly unless it's a pointer of compatible
> type!
> Solution: turn off MSVC extensions and fix the code. It shouldn't be compiling
> under gcc anyway.

Apparently I wasn't explicit enough. If you compile with /Za (disable MS
extensions & "ANSI compatibility"), you get errors in
ap_Dialog_Paragraph.cpp on line 85 and others:

        const id_val_pair rgPairs[] =
                {id_MENU_ALIGNMENT, (void*)align_LEFT},

align_LEFT is of type tAlignState, which is an enum. AFAIK, this is
perfectly valid C++. "A value of integral type or enumeration type can
be explicitly converted to a pointer." from gcc gets it right.

MSVC deviates from the standard whichever switch you use. The code
doesn't need fixing, it needs a workaround.

        /Za - Can't cast an enum to ptr-to-void
        /Ze - Loop header vars have scope of containing block

This archive was generated by hypermail 2b25 : Tue Aug 07 2001 - 12:47:50 CDT