setting a bit doesn't work

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:setting a bit doesn't work

Post by distantvoices »

Solar wrote:
proxy wrote: some people like to put constants on the left side of comparisons for this very reason for example:

Code: Select all

if(0 == ptr) {

}
Do that in a project where you work together with me and I'll have to do you serious bodily harm.

... rest of text cut off ...
Issue threats like this when working together with me in any project and you gonna find out what "may you live in interresting times" really means. ]:-< maybe you issued a jest here, but I still don't find it funny.

I do not act very gentle with people issueing threats or slamming or shouting around at the work place for I've been mobbed once and shouted at more than I can/want to count and that's enough.

I am used to have a high opinion from you, solar. I don't want to quit doing so.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:setting a bit doesn't work

Post by Candy »

OK, the first example contained an additional error that I introduced. Nevertheless, even after modifying it into int main() { it still complains about the }. Try it out, and figure it out :)
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:setting a bit doesn't work

Post by distantvoices »

the last character of that comment is a line break, so the next line beneath is also considered a comment. the poor while. Didn't see it immediately, but the compiler showed it. *gg* Syntax highlighting is cool for discovering such stuff. *rofl*
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
jonathanmcdougall

Re:setting a bit doesn't work

Post by jonathanmcdougall »

> some people like to put constants on the left side of
> comparisons for this very reason for example:
>
> if(0 == ptr) {
>
> }
>
> this way if you accidentally forget one of the = then you will
> get an error about trying to assign to an r-value.
> it's a stylistic thing, but can be useful

imo, if you always remember to put the constant on the left side, you should not have any problem with ==...

Jonathan
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:setting a bit doesn't work

Post by Candy »

Jonathan Mcdougall wrote: imo, if you always remember to put the constant on the left side, you should not have any problem with ==...
If you always remember to use your compiler flags for warnings, you will be warned at all times for these errors, plus more. Also, this is very illogical and unusual. You will get the anger of pretty much 3/4 or more of your team for doing this. Excluding one-man teams and teams formed through this aspect of course...
mystran

Re:setting a bit doesn't work

Post by mystran »

While I'd never test for an invalid pointer with (ptr == 0) but (!ptr) instead, I much prefer writing (foo == 123) and then relying on "-Wall -Werror" combination on gcc to tell me if I did something stupid. If I actually WANT to assign in a condition, then gcc at least provides the ((foo = 123)) form, where the extra pair of parenthesis makes it clear for the reader that it should be read more carefully.
Post Reply