Link to home
Start Free TrialLog in
Avatar of Biffcool
Biffcool

asked on

Forcing standard conformance in VC6

Is there a pragma or something I can call to force VC6 to obey scoping laws in for blocks (and ifs?).

i.e.
for (int foo=0; foo<bar; foo++)
{
   //Whatever
}
// foo no longer exists
Avatar of jasonclarke
jasonclarke

I don't think VC++ implements this yet.  

I think you may be able to simulate it with some nasty #defines or something.
#define for if (FALSE) { } else for
Simply embrace it with {}.

{
for (int foo=0; foo<bar; foo++)
{
   //Whatever
}
}
// foo no longer exists

chensu, I think the point is that you probably don't want to change the source code.  You want the code that compiles on a standards conformant compiler to also compile on VC++6 without any special modifications.  

The #define allows this although it may have unpleasant implications for other parts of the code, since you can conditionally compile this code in on a non-standards conformant compiler.
Avatar of Biffcool

ASKER

I was hoping for a pragma or something similar.  I'm writing a few modules completely in standard code.  However I plan on using them in some MFC code so even a project wide setting will be less ideal.  I'm <I>naively</I> hoping to make these modules usable on as many platforms as possible, and while I can just declare everything outside of the for loops, the other way appeals to me more stylistically... which usually means Microsoft hasn't implemented it yet.
Using the macros will probably get the compiler to balk because the condition in the if is a constant value.  This will just be a warning however.
There is a link switch (/Za I think) that will put VC6 into a "more compatible" mode (it is still not conforming).  However, this switch is USELESS since with it VC6 will not even compile the C++ standard library include files that come with the compiler.
/Za and /Ze only enable and disable Microsoft extensions. They do not make the compiler any more standards conformant.

I can see no compiler options in the list that do what the question asks for.
That doesn't really help me at all then.
ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh,  jasonclarke, please check your facts before saying others are wrong.
I had a look at the documentation for /Za and /Ze before I made the comment, and I have checked again since, and they make no mention of the fact that the current behavior of the for-loop is a 'Microsoft Extension.'

I found the references in the knowledge base, and, as you say it seems the switch is worse than useless, because nothing much will compile with it, including stuff like standard headers.

I apologize for doubting your answer, although I believe Microsoft are somewhat to blaim for being to embaressed to make mention of it in their compiler documentation.
>> I believe Microsoft are somewhat to blaim
>> for being to embaressed to make mention of it in their compiler documentation.

You cannot really expect them to publicly admit that, standard-wise, VC6 is not any better than VC5...

It is also interesting why I get a 'D' for a perfectly good answer along with numerous references that prove it.  I guess it is just Biffcool's way of telling me he desn't want me to answer (or comment on)  his future questions.
Well considering that the answer was of absolutely no use to me seeing as how even the standard library won't compile it was a pretty useless answer however you seemed set on answering the question so I gave you the points take what you can get skippy.
The question was "Is there a pragma or something I can call to force VC6 to obey scoping laws in for blocks (and ifs?)"

The answer was: "Yes, there is a command line switch (/Za) but you should not use it because MS screwed up with VC6's standard library".

Considering the fact that I am in no position to rewrite neither the VC6 compiler nor its library, what answer would have satisfied you?

>> take what you can get skippy.
PLONK!
You're right of course it's my fault next time I'll specify "REMOTELY USEFUL"

The only reason I didn't give your answer an E was because I was able to gleen the useful information of _don't ever disable Microsoft extensions_ from it.