Date: Sat, 22 Jul 2023 11:39:45 +0300
int arr[2];
bool test = arr;
bool teststr = "string";
Which I came across while having a function like this:
void set_property(const char *name, const char *default_value);
void set_property_bool(const char*name, bool default_value);
Where I thought the bool one was expecting a string as second argument as
well and so I wrote:
set_property_bool("test", "true");
Which compiled fine and even worked until I decided to change it to:
set_property_bool("test", "false");
In my opinion such a conversion holds no value - since it has only one
outcome - and furthermore I think it's against C++ type safety - and even
furthermore I think currently it's only purpose is obfuscation contests or
creating hard to diagnose bugs as the case I've shown above.
bool test = arr;
bool teststr = "string";
Which I came across while having a function like this:
void set_property(const char *name, const char *default_value);
void set_property_bool(const char*name, bool default_value);
Where I thought the bool one was expecting a string as second argument as
well and so I wrote:
set_property_bool("test", "true");
Which compiled fine and even worked until I decided to change it to:
set_property_bool("test", "false");
In my opinion such a conversion holds no value - since it has only one
outcome - and furthermore I think it's against C++ type safety - and even
furthermore I think currently it's only purpose is obfuscation contests or
creating hard to diagnose bugs as the case I've shown above.
Received on 2023-07-22 08:39:57