2 ms·
The reason is that anything else is using default types and you lose your safety battle in each: int32_t x = call_returning_int(); line. Otherwise, you asse
by wruza 9y ago
The reason is that anything else is using default types and you lose your safety battle in each:
int32_t x = call_returning_int();
line. Otherwise, you assert/recover on each me-they borderline. C is a language where you have absolutely no guarantee that int or constants defined as int will fit into anything beyond int, long or long long, and then there is UB patiently waiting for your mistake. The method of handling that is to never change or fix types unless you have to, and then be careful with that.
- RcouF1uZ4gsC 9y agoThis is a perfect use for the C++ auto feature: auto x = call_returning_int();
- wruza 9y agoC had this particular feature for decades.
- louiz 9y agoNo, and it still doesn’t.
- wruza 9y agoTime to explain the joke, right? https://stackoverflow.com/questions/2192547/where-is-the-c-auto-keyword-used/2192761#2192761 https://stackoverflow.com/questions/2192547/where-is-the-c-a...
- daemin 9y agoWhat he means by that is the old definition of auto, which C++11 deprecated in favour of making it do type deduction instead. auto foo = func_returning_int(); to my knowledge worked in C because 'auto' was the lifetime keyword - like 'register' - and the default type in C is 'int'. That's why when you miss a definition in C++ the compiler warns you that there's no default int.