473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Visual .NET not complaining on a C++ semantic error

I have the following piece of codes:
for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();
Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

Thanks
Thierry

Oct 4 '05 #1
9 2266

la********@gmail.com wrote:
I have the following piece of codes:
for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();
Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.


http://msdn.microsoft.com/library/de...zcforscope.asp

Oct 4 '05 #2
la********@gmail.com wrote:
I have the following piece of codes:
for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();
Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.


You need to learn to use your compiler better. By default it has this
"feature" as an "extension". Disable language extensions and you'll get
an error message. Also, consider asking compiler-specific questions in
a newsgroup for that compiler (microsoft.public.vc.language, here)

V
Oct 4 '05 #3
la********@gmail.com wrote:

I have the following piece of codes:

for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();

Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.


Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler switch.

AFAIK, later versions of VC compilers changed that.
--
Karl Heinz Buchegger
kb******@gascad.at
Oct 4 '05 #4
On 4 Oct 2005 07:16:42 -0700, la********@gmail.com wrote:
I have the following piece of codes:
for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();
Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.

Thanks
Thierry


There have been many times when I wished I could redefine "I" globally
elsewhere...<g>.

Seriously, though, I would first look for a compiler switch which
turns off the ANSI "for" scope rules regarding the above.

Secondly, I suspect pollution of the global namespace as the culprit.
I would look for any header files, included either directly or
indirectly by your own headers (but including your own headers) which
have "using namespace <whatever>;" in them. One of these MIGHT have
declared "i" at global scope within the local namespace or else at
global scope.

Other than that -- well, perhaps you *did* declare an "i" (or was it
an "I"?? <g>) somewhere at global scope...

--
Bob Hairgrove
No**********@Home.com
Oct 4 '05 #5
Thanks, that helps, I wasn't aware of that.

Thierry

Oct 4 '05 #6
Ook

"Maxim Yegorushkin" <ma***************@gmail.com> wrote in message
news:11********************@f14g2000cwb.googlegrou ps.com...

la********@gmail.com wrote:
I have the following piece of codes:
for (int i = 0; i < 10; i++)
function1();

for (i = 0; i < 5; i++)
function2();
Technically, I should be getting an error in the 2nd for loop but when
I compile the above with Visual .NET, everything compiles fine.

Any ideas what's wrong? I did not define I globally elsewhere.


http://msdn.microsoft.com/library/de...zcforscope.asp


That is exactly what it was. Project Properties -> Configuration
Properties -> c/c++ -> Language -> Force Conformance In For Loop Scope
defaults to No. Ack, I wonder how many mistakes I made in my code because I
didn't know about this?
Oct 4 '05 #7
Im using 2005b2, default config

error C2065: 'i' : undeclared identifier

you have prob messed up something. vs isnt so ...stupid ;)
Oct 4 '05 #8

Karl Heinz Buchegger wrote:

[]
Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler switch.


Visual C++ 6.0 does not have a switch for that.

The usual solution for this compiler was:

#define for if(0); else for

Oct 5 '05 #9
Maxim Yegorushkin wrote:
Karl Heinz Buchegger wrote:

[]
Any chance you are using Visual C++ 6.0 compiler?
That compiler had that 'bug'. Microsoft had a 'good reason' keep that
old way of treating loop variables. It can be changed by a compiler
switch.
Visual C++ 6.0 does not have a switch for that.


Actually, it does. It's called "Disable Language extensions". OT here,
but still. Of course, it causes all kinds of trouble if you try to use
some other MS libraries...
[...]


V
Oct 6 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
0
by: Sheila Jones | last post by:
Hello, I have an XSLT file to transform XML into HTML. Part of the transformation includes a client side script, which is enclosed in a CDATA section. To illustrate, here is part of the file: ...
140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
6
by: Peter Ross | last post by:
I get a link error when I try and create a module of the following very simple managed C++ code. I can't imagine a more minimum piece of code, so I imagine that this is some sort of compiler bug....
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
10
by: Smokey Grindel | last post by:
I've read about 3 blogs now that says VS2005 SP1 includes the AJAX framework in the update, yet I don't see it anywhere... is it actually included in the Service Pack or do I still need to install...
12
by: rshepard | last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding the solution in the docs I have here. Data are assembled for writing to a database table. A representative tuple looks...
10
by: kimiraikkonen | last post by:
Visual C#.NET 2005 express has some issues, unlike VB.NET 2005 has none of them: The most annoying one is: For example if there's a coding error, it must be reported at the buttom of the screen...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.