What "for" ?
-
Just came across this (C++) #define for if( false );else for :omg:
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb:omg: One of the most horrific, IMHO.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Just came across this (C++) #define for if( false );else for :omg:
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverbThis can be fixed easily: #define false true There ya go ...
-
Just came across this (C++) #define for if( false );else for :omg:
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverbThat's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly). -
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).So the real WTF is that the author didn't write a paragraph long comment explaining the reason behind the definition?
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
-
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).That's enlightening... It still makes it a horror, but it goes back to it being Microsoft's horror for the variable scope issue in VC6. Still, a comment by the #define in the original would have been helpful.
Faith is a fine invention For gentlemen who see; But microscopes are prudent In an emergency! -Emily Dickinson
-
Just came across this (C++) #define for if( false );else for :omg:
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverbSimilar than the macro style used for macro's that need to be an explicit statement. Eg:
#define ASSERT(f) \
do { \
if (!(f) && assertFailedOnLine (THIS_FILE, __LINE__)) \
FatalExit (0); \
} while (0)This forces the 'user' to only use ASSERT(x) as a statement, as the ; is required. See link below for more info, or Google for "while(0)". http://www.thescripts.com/forum/thread215019.html[^]
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
That's enlightening... It still makes it a horror, but it goes back to it being Microsoft's horror for the variable scope issue in VC6. Still, a comment by the #define in the original would have been helpful.
Faith is a fine invention For gentlemen who see; But microscopes are prudent In an emergency! -Emily Dickinson
David Kentley wrote:
but it goes back to it being Microsoft's horror for the variable scope issue in VC6
It still cannot be used in C, C++ does allow it. GCC with GNU extensions does allow it too.
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
This can be fixed easily: #define false true There ya go ...
-
So the real WTF is that the author didn't write a paragraph long comment explaining the reason behind the definition?
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
-
It didn't have to be a paragraph long, but at least one line would have been nice. Excellent exhibit for the next time someone tells you "real coders don't comment".
everything is relative for most things a single line it adequate but for something that looks to be a major WTF though I prefer a generous explanation.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
-
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).MrMarco wrote:
one of my workmates:
:cool: Thanks to him for the explanation and to you for posting it here... I find it awesome that a true reason has been found to justify the mere existence of this line of code.
MrMarco wrote:
The macro you see is a workaround for this
:doh: So, we are speaking about using awful code to counter awful bugs. :rolleyes: Probably the climax of the coding horror (well, no, it could have been VB :) ).
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb -
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).MrMarco wrote:
That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6.
Exactly! However, in defense of good ol' VC6, it was released before the Standard, and in early 1990's some other compilers were doing the same thing.
-
MrMarco wrote:
one of my workmates:
:cool: Thanks to him for the explanation and to you for posting it here... I find it awesome that a true reason has been found to justify the mere existence of this line of code.
MrMarco wrote:
The macro you see is a workaround for this
:doh: So, we are speaking about using awful code to counter awful bugs. :rolleyes: Probably the climax of the coding horror (well, no, it could have been VB :) ).
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverbRage wrote:
So, we are speaking about using awful code to counter awful bugs.
That was really a feature, not a bug :) (see my other comment in this thread). It became a bug only after the Standard was released.
-
Just came across this (C++) #define for if( false );else for :omg:
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb:wtf:
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
So the real WTF is that the author didn't write a paragraph long comment explaining the reason behind the definition?
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
dan neely wrote:
the real WTF is that the author didn't write a paragraph long comment explaining the reason behind the definition?
Exactly. I'd hate to be a newcomer on the project and run across that :laugh:
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).interesting and enlightening... but then just for the sake of a little simplicity, it could have been written like #define for if(true)for; and yes, this thing should have been documented. I saw a similar thing somewhere else where there was code like..
do
{
//code
}
while(0);This was just to define a scope for the variable declared with in the block. MS VC compilers do allow braces without any keyword behind them but in some flavors of C/C++, you just can't put braces in your code without a construct.
-
interesting and enlightening... but then just for the sake of a little simplicity, it could have been written like #define for if(true)for; and yes, this thing should have been documented. I saw a similar thing somewhere else where there was code like..
do
{
//code
}
while(0);This was just to define a scope for the variable declared with in the block. MS VC compilers do allow braces without any keyword behind them but in some flavors of C/C++, you just can't put braces in your code without a construct.
Thats a usefull code method to avoid using goto. A failure is followed by a break and you jump out of the loop. However, I use non keyworded braces my self for local vars, but also to bracket code that has a particular purpose, or I want to be thought of as distinct from the rest.
Morality is indistinguishable from social proscription
-
That's the answer from one of my workmates: That's a workaround for one of the more braindead shortcomings of Microsoft Visual C++ 6. In ISO/ANSI C++, if you declare a loop variable inside a for-statement, that variable goes out of scope at the end of the loop, i.e. you can do this:
for ( int i = 0; i < x; ++i ) { // Code } for ( int i = 0; i < y; ++i ) { // Code }
MSVC 6 chokes on this - "variable redefinition". The macro you see is a workaround for this, "forcing" the loop variable into the else-scope (which MSVC 6 handles correctly).A fair criticism, but remember that Visual C++ 6.0 was written before the standard was actually finalized, and at the time it was released that was one of the breaking changes.