r/badcode • • Jul 30 '21

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

Post image
648 Upvotes

84 comments sorted by

View all comments

Show parent comment

8

u/[deleted] Jul 30 '21
bool condition = true;
if (condition = false)
{
    ...
}

3

u/[deleted] Jul 30 '21

Ok cool, i totally took for granted we were talking about integers

Now it makes sense 👍🏻

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

-1

u/AutoModerator Jul 30 '21

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/fasync, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.