redefinition, different types

G

Gernot Frisch

What does the standart say:

for (long i=0; i<0; ++i) ;
for (myclass i=0; i<0; ++i);

is it allowed? i only is defined in the for-loop space, isn't it?
VC6 gives me an *error*, not just a stupid warning.


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
J

John Harrison

Gernot Frisch said:
What does the standart say:

for (long i=0; i<0; ++i) ;
for (myclass i=0; i<0; ++i);

is it allowed? i only is defined in the for-loop space, isn't it?
VC6 gives me an *error*, not just a stupid warning.

Standard says its OK.

The best solution on VC++ 6 is

#define for if (0); else for

at the top of every source file. This effectively puts each for loop inside
its own scope.

John
 
G

Gernot Frisch

Standard says its OK.
The best solution on VC++ 6 is

#define for if (0); else for

at the top of every source file. This effectively puts each for loop
inside
its own scope.

yuck! will this give any problems? I can't see any right now. I'll
include this in my afx.h for VC6. Thank you.
-Gernot
 
J

John Harrison

Gernot Frisch said:
yuck! will this give any problems? I can't see any right now. I'll
include this in my afx.h for VC6. Thank you.
-Gernot

Standard says its illegal to #define a keyword. However I've used this
extensively on VC++ 6 and its never caused any problems for me.

john
 
U

Unforgiven

Gernot Frisch said:
What does the standart say:

for (long i=0; i<0; ++i) ;
for (myclass i=0; i<0; ++i);

is it allowed? i only is defined in the for-loop space, isn't it?
VC6 gives me an *error*, not just a stupid warning.

This is indeed a non-conformance bug in VC6. It has been fixed in later
versions, but only when the /Za or /Zc:forScope compiler options are
specified.
 
H

Howard

JKop said:
VC6 isn't a C++ compiler.


-JKop

So what is it...a Pascal compiler? :)

(I'll admit it fails to meet the standards of a "conforming" compiler, but
are there any that *are* completely conforming?)

-Howard
 
J

JKop

Howard posted:
So what is it...a Pascal compiler? :)

(I'll admit it fails to meet the standards of a "conforming" compiler,
but are there any that *are* completely conforming?)

-Howard

For the love of God I ALWAYS ALWAYS ALWAYS write loops one
after the other that define a counter called i, eg:

for (int i =0; ;)...
....

for (unsigned char i = 5;...


If a certain compiler doesn't deal with that as it should,
it can go and shite!


-JKop
 
H

Howard

JKop said:
Howard posted:


For the love of God I ALWAYS ALWAYS ALWAYS write loops one
after the other that define a counter called i, eg:

for (int i =0; ;)...
...

for (unsigned char i = 5;...


If a certain compiler doesn't deal with that as it should,
it can go and shite!

Nice sentiment, although I think you meant "shit"? But personally I have
several third-party SDK's that still require VC++6, so I'm stuck with it
(for now). Fortunately, they're moving (slowly) to VC++.NET, which at least
gets this part right. But since I share source code between those, I still
have code that declares my loop variable once, the re-uses it for subsequent
loops. (One might argue, however, that if you have two loops in one
function, perhaps you ought to have two functions instead...?)

-Howard
 
J

Jack Klein

Standard says its OK.

The best solution on VC++ 6 is

#define for if (0); else for

at the top of every source file. This effectively puts each for loop inside
its own scope.

John

While this works on every implementation I know of, are you aware that
this makes a C++ program ill-formed?

========
[lib.macro.names] 17.4.3.1.1 Macro names

1 Each name defined as a macro in a header is reserved to the
implementation for any use if the translation unit includes the
header.

2 A translation unit that includes a header shall not contain any
macros that define names declared or defined in that header. Nor shall
such a translation unit define macros for names lexically identical to
keywords.
========
 
J

Jack Klein

Standard says its illegal to #define a keyword. However I've used this
extensively on VC++ 6 and its never caused any problems for me.

john

Oh, you did know.
 
G

Gernot Frisch

JKop said:
(One might argue, however, that

Nah!! I hate writing new functions, giving new names, having a huge
function-name tree at my classes-view. I don't mind if I can write:
long i;
for (i...
for (i...

But if I need i to have different types, this bug's a PITA. Using Za
option will help? I'll try that. I don't like to use VC6, but I have
one project that only rund on Win9x if compiled with VC6. With .net7.1
it crashes before the Mainframe gets created...
-Gernot
 
J

Jerry Coffin

[ ... ]
But if I need i to have different types, this bug's a PITA. Using Za
option will help? I'll try that. I don't like to use VC6, but I have
one project that only rund on Win9x if compiled with VC6. With .net7.1
it crashes before the Mainframe gets created...

The good news is that the /Za flag really does enforce the correct
scope for variables defined in the header of a for loop. The bad news
is that (most of?) Microsoft's headers violate other rules that /Za
enforces, thus rendering the flag useless with anything but the most
trivial code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top