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
BiffcoolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

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

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

jasonclarkeCommented:
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.
0
BiffcoolAuthor Commented:
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.
0
danny_pavCommented:
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.
0
alexoCommented:
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.
0
jasonclarkeCommented:
/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.
0
BiffcoolAuthor Commented:
That doesn't really help me at all then.
0
alexoCommented:
Bifcool, /Za is the option you need.
What? You doubt me?  I'm hurt...
OK, let's give some proof then:

1) Check http://support.microsoft.com/support/kb/articles/q167/7/48.asp
    To see what MS has to say about it.

2) http://www.wdj.com/current/bug.html says:
>> As you point out in the article, the correct for-loop scoping can be
>> achieved with the /Za switch, but then you can't compile any Windows
>> program, so what use is that?

3) Check the following usenet posts (courtesy of deja):
    http://www.deja.com/=dnc/getdoc.xp?AN=438946076
    http://www.deja.com/=dnc/getdoc.xp?AN=400355173
    http://www.deja.com/=dnc/getdoc.xp?AN=404482862
    http://www.deja.com/=dnc/getdoc.xp?AN=265106416

4) See http://www.mindspring.com/~brahms/codeprac/build.html#cleanCompile
    for another opinion.

So your answer is, as I said before:
Yes, it is *possible* to have the correct behavior (using /Za) but it is not *feasible* since almost no "real" program will compile with it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexoCommented:
Oh,  jasonclarke, please check your facts before saying others are wrong.
0
jasonclarkeCommented:
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.
0
alexoCommented:
>> 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.
0
BiffcoolAuthor Commented:
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.
0
alexoCommented:
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!
0
BiffcoolAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.