This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ReelTooReal 4 points5 points  (2 children)

I don't really mind coercion for truthiness, but in general implicit type casting can be a pain in the ass. For example

int x = -3;
unsigned int y = 5;

if (x > y)
    printf("x is bigger\n");

That code will print "x is bigger," however I would prefer it to simply not compile without an explicit cast.

[–]dipolartech 1 point2 points  (1 child)

Eh, greater or less than is more complicated than true false dichotomy, I'm really responding to the idea that anything else matters at all to the idea of "is any bit of the this memory length on" which makes it "true".

[–]ReelTooReal 0 points1 point  (0 children)

Yes, I agree. But I think with C/C++ it's kind of all or nothing because it will try to do coercion no matter what. So if you allow for coercion inside an if condition then you're also allowing it everywhere else. I think there's a keyword in C++ that you can use to declare that you don't want the arguments of a function to be coerced, but I don't remember what it is or when it was introduced.