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 2824
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******** ********@newsre ad1.news.pas.ea rthlink.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****@waltert ross.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.*******@warw ick.ac.uk> wrote in message news:<ca******* ***@wisteria.cs v.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 (int i=0, flip = 0; i < a.size(); ++i)
{
|
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 in global
space, therefore it is not a global variable, yes? Even if it was
global, how would it get from one function to another? In PHP
variables are copied by value. Are they copied by reference in
Javascript?
<SCRIPT LANGUAGE="JavaScript">
|
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 value of y
(works well).
create table test (a integer)
@
create table debug1 (a integer)
@
create trigger test_1 after insert on test referencing new as ins for
| |
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.
Recently we (my fellow team members & I) observed an
InvalidOperationException - 'collection has been modified', however it
wasn't immediately obvious why this would be occuring. There are no
modifications occuring within the loop and there is...
|
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, because
according to the rule stated in PHP manual(http://www.php.net/manual/
en/language.variables.scope.php): The scope of a variable is the
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |