[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Forcing standard conformance in VC6

Posted on 1999-07-21
16
Medium Priority
?
282 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
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

607 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