Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Forcing standard conformance in VC6

Posted on 1999-07-21
16
Medium Priority
?
280 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:Biffcool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +2
16 Comments
 
LVL 9

Expert Comment

by:jasonclarke
ID: 1200718
I don't think VC++ implements this yet.  

I think you may be able to simulate it with some nasty #defines or something.
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1200719
#define for if (FALSE) { } else for
0
 
LVL 23

Expert Comment

by:chensu
ID: 1200720
Simply embrace it with {}.

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

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:jasonclarke
ID: 1200721
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
 

Author Comment

by:Biffcool
ID: 1200722
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
 
LVL 3

Expert Comment

by:danny_pav
ID: 1200723
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
 
LVL 11

Expert Comment

by:alexo
ID: 1200724
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
 
LVL 9

Expert Comment

by:jasonclarke
ID: 1200725
/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
 

Author Comment

by:Biffcool
ID: 1200726
That doesn't really help me at all then.
0
 
LVL 11

Accepted Solution

by:
alexo earned 20 total points
ID: 1200727
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
 
LVL 11

Expert Comment

by:alexo
ID: 1200728
Oh,  jasonclarke, please check your facts before saying others are wrong.
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 1200729
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
 
LVL 11

Expert Comment

by:alexo
ID: 1200730
>> 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
 

Author Comment

by:Biffcool
ID: 1200731
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
 
LVL 11

Expert Comment

by:alexo
ID: 1200732
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
 

Author Comment

by:Biffcool
ID: 1200733
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question