r/badcode • • Jul 30 '21

c++ from the codebase that brought you 'std::string comma = "(";'

Post image
654 Upvotes

84 comments sorted by

View all comments

Show parent comment

3

u/MorphTheMoth Jul 31 '21

you can do in with integers too, dont know why you would but this works:

int a = 0;
if( (a=2) == 2 )  // true

2

u/[deleted] Jul 31 '21

Well technically the truth but in this case you need to actively add parentheses which kind of removes the "by mistake" aspect

1

u/MorphTheMoth Jul 31 '21

oh right, the c# compiler gives an error if you implicitly cast an int into a bool