4 ms·
Have you ever actually encountered a bug involving accidentally passing a pointer to a 'bool' function argument? I've seen many obscure kinds of bugs, but don'
by comex 13y ago
Have you ever actually encountered a bug involving accidentally passing a pointer to a 'bool' function argument? I've seen many obscure kinds of bugs, but don't remember ever in my life seeing one of those- so I suspect this is a red herring.
(And of course if the value passed happens to be an int rather than a pointer, typedefing bool to int won't save you!)
edit: And as mentioned in the rest of the thread, while it's unjustifiably confusing to, say, pass 'p' as a boolean parameter rather than 'p != NULL', it's not unreasonable to do something like
typedef int bool;
bool foo_enabled;
void set_foo_enabled(bool enabled) {
if(enabled == foo_enabled) return;
/* new value is different, do some work */
}
set_foo_enabled(1);
...
set_foo_enabled(flags & ENABLE_FOO);
Though I haven't come across this kind of bug in practice either.
- bzbarsky 13y agoI've encountered a bug like that when the callee was converted from taking a pointer to taking a bool and the caller was not updated because it compiled fine...
- deleted 13y ago[deleted]