== vs =
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
That's nothing. Years ago, I spent half a day figuring out why this loop only exected one iteration:
for (int i=0; i<10; i++);
{
... do something
}BTW, isn't there a compiler warning for "are you sure you want to do an assignment here? Is your warning level set to the highest level? Marc Pensieve
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
Turn your warning level up to 4, and the compiler will flag those problems. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
Maximilien wrote:
set your compiler warning to "level 4"
- I never understood why they even give you different warning levels as an option 2) I've never understood why people don't use the highest warning level possible. 3) STL. Oh yeah. Marc Pensieve
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
Try to get in the habit of putting constants and functions to the left of
==
. Not only will it instantly flag such unintended assignments as errors at any warning level, but it often makes it easier to recognize them while scanning through code.---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
-
Try to get in the habit of putting constants and functions to the left of
==
. Not only will it instantly flag such unintended assignments as errors at any warning level, but it often makes it easier to recognize them while scanning through code.---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Is 1 == 2 more natural than 2 == 1?
-
Ugh. I hate that. I can see the minor potential benefits, but god it's awful and completely unnatural :~
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this:
if((((a/b)+c)==(d))||(((a*c)+b)==(z)))
- i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
-
I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this:
if((((a/b)+c)==(d))||(((a*c)+b)==(z)))
- i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
Shog9 wrote:
(((a/b)+c)==(d))||(((a*c)+b)==(z))
People who write expressions like that only express one thing...
-
Shog9 wrote:
(((a/b)+c)==(d))||(((a*c)+b)==(z))
People who write expressions like that only express one thing...
I'm still hoping it's a secret pining for Lisp...
---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
-
I'm still hoping it's a secret pining for Lisp...
---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
At least you're forced to in Lisp... :)
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
This would solve all your problems :-
class T
{
. . .
bool operator = (const T& t)
{
return operator ==(t);
}
. . .
}:rolleyes: :rolleyes: :rolleyes: Regards, Nish
Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
The Ultimate Grid - The #1 MFC grid out there! -
This would solve all your problems :-
class T
{
. . .
bool operator = (const T& t)
{
return operator ==(t);
}
. . .
}:rolleyes: :rolleyes: :rolleyes: Regards, Nish
Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
The Ultimate Grid - The #1 MFC grid out there!Well thanks everyone for your suggestions to turn up the warning level. The reason I didn't catch it before is because I'm using a class that someone else wrote that uses lots of old string functions. And when I build it, the output window gets filled with warnings about how this function is unsafe, and that function is unsafe, and this function will make your machine blow up, etc.! Thanks! Rich
-
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '==' !! :mad: Uhg!
Troposphere wrote:
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '=='
I love you! Apparently there are at least 2 mortals who come to this site on a regular basis. Stuff like that burns my butt when I catch myself at it.
I only read CP for the articles. Code-frog System Architects, Inc.
-
Well thanks everyone for your suggestions to turn up the warning level. The reason I didn't catch it before is because I'm using a class that someone else wrote that uses lots of old string functions. And when I build it, the output window gets filled with warnings about how this function is unsafe, and that function is unsafe, and this function will make your machine blow up, etc.! Thanks! Rich
Bloody typical with C++ if you ask me. One more reason to love C# if you ask me, relevant and concise error and warning message !
-
Troposphere wrote:
I just spent an hour and a half debugging a problem in C++ that was caused by using the '=' instead of the '=='
I love you! Apparently there are at least 2 mortals who come to this site on a regular basis. Stuff like that burns my butt when I catch myself at it.
I only read CP for the articles. Code-frog System Architects, Inc.
code-frog wrote:
I love you! Apparently there are at least 2 mortals who come to this site on a regular basis.
LOL Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
That's nothing. Years ago, I spent half a day figuring out why this loop only exected one iteration:
for (int i=0; i<10; i++);
{
... do something
}BTW, isn't there a compiler warning for "are you sure you want to do an assignment here? Is your warning level set to the highest level? Marc Pensieve
-
I don't really see much of a difference, so i use it. What is it that you find unnatural? (now on the other hand, i absolutely hate "safe" code that looks like this:
if((((a/b)+c)==(d))||(((a*c)+b)==(z)))
- i can understand not being entirely clear on operator precedence, but at some point you'd hope they'd stop typing and read up on it)---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums
Well, at least I would write it as:
if((((a / b) + c) == d) ||
(((a * c) + b) == z))I learned C back in the day when operator precedence enforcement was hit-or-miss in some compilers (yes, I'm that freakin' old). I was also programming in FORTRAN, Ada, and LISP at the time. It was just too bloody hard to remember the different rules for each language, so I learned to fully parenthesize. It could be worse. Here's an example of the coding style of one of my coworkers:
if (x == 2 || x == 6 && y > 5) for (int i = -1; i < 10; ++i)
InvokeMethod(i,x,y); else InvokeMethod2(x);He avoids braces '{}' and parentheses whenever possible, and just strings everything together on one line like a sentence. He's also one of these object-oriented-out-the-wazoo types, who never puts more than four or five lines of code in a single function. His code is almost impossible to follow. The only saving grace is he does adhere to our naming conventions.
Software Zen:
delete this;
-
Bloody typical with C++ if you ask me. One more reason to love C# if you ask me, relevant and concise error and warning message !
Just wait. C/C++ has had thirty years to collect warnings and errors, not to mention rules that makes it difficult for them to be specific and clear. C# will get there[^] too...
---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums