Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

airjy

for and visual c++ 6.0

This topic is 5407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

today i started programming under windows with visual c++ 6.0 Before, i''ve only used borland or g++ under linux, and i''ve found something strange. if i do : for(int i=0;i<10;i++) { ... } i can still access i after the } and i cannot declare int i after that for.. that''s annoying because if i have to make another for just after, i have to use for(i=0:i<10;i++) {...} That code can''t be compiled with g++ under linux, and if i use int i in the 2nd for, visual c++ won''t compile with the following error. error C2374: ''i'' : redefinition; multiple initialization any ideas why visual c++ act so strangely? i haven''t touched the compilations options, they are the ones by default when creating an empty project.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I dont understand what the problem with that is, why not just say.

int i;
for(i=0;i<10;i++)
{
...

}
for(i=0;i<10;i++)
{
...

}
or


for(int i=0;i<10;i++)
{
...

}
for(int j=0;j<10;j++)
{
...

}

???

Share this post


Link to post
Share on other sites
I think it was

for(int i = 0; i < 10; i++)
{...}

for(i = 11; i < 20; i++) // notice i left out "int"
{...}

Share this post


Link to post
Share on other sites
my problem is that the scope for a variable is between { and }
maybe i''m wrong but i''ve always been told that
if i do
for(int i=0;i<10;i++)
{
...
}

//there the variable i doesn''t exist, so i can make another one.
// for ex
int i = 5;

with g++ it''s ok it follows that rule

but with visual c++
the variable i still exists after the }
and i don''t want that to happen because the code won''t be portable under linux.


after the 1st for
i can''t make int i=5, because it says that the variable i already exists. Maybe it''s a feature of visual c++, but i would like the compiler to act as the norm says, and i don''t know how...

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
I dont understand what the problem with that is, why not just say.
or


for(int i=0;i<10;i++)
{
...

}
for(int j=0;j<10;j++)
{
...

}

???


I think this jumps as double declaration in VC++

Share this post


Link to post
Share on other sites
yes it''s double declaration ant that''s the pb...
maybe i''ll have to swith to visual studio .net if that''s fixed.
maybe for you it''s not a bug, but for me it''s a huge one

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by owl
quote:
Original post by Anonymous Poster
I dont understand what the problem with that is, why not just say.
or


for(int i=0;i<10;i++)
{
...

}
for(int j=0;j<10;j++)
{
...

}

???


I think this jumps as double declaration in VC++



I dont think that is a double decleration, i changed the variable name to ''j'' the second time.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
quote:
Original post by owl
quote:
Original post by Anonymous Poster
I dont understand what the problem with that is, why not just say.
or


for(int i=0;i<10;i++)
{
...

}
for(int j=0;j<10;j++)
{
...

}

???


I think this jumps as double declaration in VC++



I dont think that is a double decleration, i changed the variable name to ''j'' the second time.



Oh, look at that!

Share this post


Link to post
Share on other sites
This was one of those controversial "breaking changes" between pre-ansi and ansi C++ that microsoft chose to support the old behavior for VC6. I remember seeing an article somewhere on microsoft.com sugesting that you do the following trick/hack/kludge to get the right behavior on VC6:

#define for if ( true ) for

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!