When I have a couple of for loops sequentially, and they use the same
counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable
redeclaration. I thought that the i stayed within the scope of the for loop?
The same code on gcc doesn't give this error (not on the default settings at
least). Is VC being fussy, and can I turn this fussiness off?
--
Nick H 7 2796
Nick Howes wrote: When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable redeclaration. I thought that the i stayed within the scope of the for loop? The same code on gcc doesn't give this error (not on the default settings at least). Is VC being fussy, and can I turn this fussiness off?
It's a VC6 bug. Download the free VC++ Toolkit 2003 from Microsoft's site,
and use that in place of the VC6 compiler. It comes with the full VC++ 2003
Pro edition optimizing compiler and standard library.
- Pete
"Pete C." <x@x.x> wrote in message
news:D9****************@newsread1.news.pas.earthli nk.net... Nick Howes wrote: When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable redeclaration. I thought that the i stayed within the scope of the for loop? The same code on gcc doesn't give this error (not on the default settings at least). Is VC being fussy, and can I turn this fussiness off? It's a VC6 bug.
It's not really a bug, it's a relic of pre-standard C++.
Download the free VC++ Toolkit 2003 from Microsoft's site, and use that in place of the VC6 compiler. It comes with the full VC++
2003 Pro edition optimizing compiler and standard library.
If you don't want to switch compilers, an alternative is this macro. Place
it at the beginning of each file.
#define for if (0); else for
Nick Howes 2004-06-15 : When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable redeclaration. I thought that the i stayed within the scope of the for loop? The same code on gcc doesn't give this error (not on the default settings at least). Is VC being fussy, and can I turn this fussiness off?
You are a bit off-topic here, but anyhow...
I don't know about VC6, but in VC .NET it's an option in project
properties -> C/C++ -> language. I don't know it's precise naming in
English since I have it in Italian, but it should be something like
"impose for cycle scope conformity".
By default it's turned off, which in my opinion is plain wrong.
I wish I knew a way to have it turned on by default for every new project
I start...
Walter Tross
"Walter Tross" <wa****@waltertross.com> wrote in message
news:sw***************************@40tude.net... Nick Howes 2004-06-15 :
When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of
variable redeclaration. I thought that the i stayed within the scope of the for
loop? The same code on gcc doesn't give this error (not on the default
settings at least). Is VC being fussy, and can I turn this fussiness off?
You are a bit off-topic here, but anyhow... I don't know about VC6, but in VC .NET it's an option in project properties -> C/C++ -> language. I don't know it's precise naming in English since I have it in Italian, but it should be something like "impose for cycle scope conformity".
Sorry about the OT-ness, should've looked up a visual studio newsgroup.
Thanks everyone for your advice anyhow, there's no such option in VC6 but i
will look up that VC++ Toolkit 2003 and have a look.
Cheers
Nick H
Walter Tross wrote: Nick Howes 2004-06-15 :
When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable redeclaration. I thought that the i stayed within the scope of the for loop? The same code on gcc doesn't give this error (not on the default settings at least). Is VC being fussy, and can I turn this fussiness off?
You are a bit off-topic here, but anyhow...
<snip>
au contraire --
This is very *much* on topic. Prior to the (pre)standard change to for-loop
scoping rules, variables declared in a for-loop were still in scope outside of
the loop.
This conformity issue, in part, is due to the very *long* time that it took for
the standard to actually be finalized/approved/ratified in the 90's.
"Nick Howes" <n.*******@warwick.ac.uk> wrote in message news:<ca**********@wisteria.csv.warwick.ac.uk>...
[ ... ] Sorry about the OT-ness, should've looked up a visual studio newsgroup. Thanks everyone for your advice anyhow, there's no such option in VC6 but i will look up that VC++ Toolkit 2003 and have a look.
VC++ 6 has an option (/Za) that enforces the correct scope for
variables defined in the header of a for loop (etc.) The problem is
that when you turn this switch on, it enforces a number of other
rules, and its standard headers (among other things) won't compile
when those rules are enforced -- the result is that even though the
compiler itself has the capability, the remainder of the
implementation renders it unusable.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Pete C. wrote: Nick Howes wrote:
When I have a couple of for loops sequentially, and they use the same counter name, i.e. for(int i=0; i<x; i++), Visual C++ complains of variable redeclaration. I thought that the i stayed within the scope of the for loop? The same code on gcc doesn't give this error (not on the default settings at least). Is VC being fussy, and can I turn this fussiness off?
It's a VC6 bug. Download the free VC++ Toolkit 2003 from Microsoft's site, and use that in place of the VC6 compiler. It comes with the full VC++ 2003 Pro edition optimizing compiler and standard library.
I know we're getting OT here, but when you say "use that in place of the
VC6 compiler" do you mean that the v13 MS C++ compiler is compatible
with Visual Studio 6, i.e. interchangeable with the v12 compiler? I
wasn't aware of that; it would be very interesting to me if true.
--
Mike Smith This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arthur |
last post by:
>>>a=
>>> for p in a:
print p
1
2
3
>>> p
3
My naive expectation was that p would be 'not defined' from outside
|
by: Arthur J. O'Dwyer |
last post by:
I was paging through Coplien's book "Advanced C++ Programming Styles
and Idioms" this afternoon and found some code that looked something
like
void sort(vector<foo> a)
{
int flip;
do {
for...
|
by: Wenjie |
last post by:
Hello,
We had a code review with the argument of
whether "i" is out of scope as illustrated
below:
for (int i=0; i<2004; i++)
{
doSomething(i);
}
|
by: lawrence |
last post by:
I'm learning Javascript. I downloaded a script for study. Please tell
me how the variable "loop" can have scope in the first function when
it is altered in the second function? It is not defined...
|
by: Gustavo Randich |
last post by:
The following seems to be a bug. The execution returns rows 1,2. It
should return 1,1. In fact, if I run the code within a stored procedure
alone (not in a trigger), the loop doesn't overwrite the...
|
by: bughunter |
last post by:
This is partly 'for the record' and partly a query about whether the
following is a bug somewhere in .Net (whether it be the CLR, JITter, C#
compiler). This is all in the context of .Net 1.1 SP1.
...
|
by: Michael Moreno |
last post by:
Hello,
Would you know what is best practice please between say:
CODE 1:
TimeSpan ts;
for (i=0; i<1000; i++)
{
|
by: Erik de Castro Lopo |
last post by:
Hi all,
Consider the following code snippet:
do
{
int r = rand () ;
} while (r != 0) ;
It seems the compiler I'm using (GCC) does realise that the
|
by: pauldepstein |
last post by:
On my visual c++ compiler, I compiled code which contained something
like
for( int i =0; i < 5; i++)
{ double x =5;}
I expected it to give a compiler error because x is being redefined
|
by: ray |
last post by:
Hi, all,
foreach($array as $k =$v) {
$foo = ...;
}
echo $foo;
Is it allowed to access the $foo variable that is created within the
loop from outside of the loop? I think it isn't allowed,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |