4 ms·
I wonder what would happen if i put hand into fire. But I have never done it in my life, because it might cause 'undefined behaviour'. In my years of working w
by me_me_me 6y ago
I wonder what would happen if i put hand into fire.
But I have never done it in my life, because it might cause 'undefined behaviour'.
In my years of working with C its always the 'look how smart I am code' causes issues.
Keep it clean and simple. Avoid complexity and fluff features of C. And you will not going to have deal with exotic bugs.
- cortesoft 6y agoI am pretty sure your hand going in fire is pretty defined behavior
- me_me_me 6y agoIs it though, for yourself/your body. Is putting hand into a fire something you experienced and internalized?
- cortesoft 6y agoNo, but it is part of the spec
- perl4ever 6y agoOf all the possible things that could happen to me, I am very confident that only a small subset could result, so it is pretty well defined. Nasal demons, for instance, are not on the menu.
- me_me_me 6y agoWe are really straying off actual point. Why would you not actively avoid undefined behaviour and instead take risk. Zeroing out variables, checking pointers coming from external modules etc. Not rallying on a compiler to resolve fancy stuff. Like the example: void contains_null_check(int P) { int dead = P; if (P == 0) return; P = 4; } Leave declarations uninitialized or zeroed Check input. Work with data. void contains_null_check(int P) { int dead; if (P == 0) return; int dead = P //work P = 4; } This leaves less space for error/interpretation and IMHO it keeps code cleaner. Any fancy optimizations should be used only for critical path and only when absolutely necessary.