4 ms·
Frankly, the C standards ctte went off the deep end when they effectively banned NULL to memset etc (obv with zero length). Not because these functions couldn'
by RustyRussell 4y ago
Frankly, the C standards ctte went off the deep end when they effectively banned NULL to memset etc (obv with zero length).
Not because these functions couldn't handle it, but because this assertion simplifies optimizations elsewhere.
This has required adding extra checks in my code, found mainly by trial and error, and has made it less readable and less optimal.
Finally, the checked arithmetic operations returning false on success is a horror show. Fortunately it will be found on the first time the code is run, but that's a damnably low bar :(
- ericpauley 4y ago> Finally, the checked arithmetic operations returning false on success is a horror show. This seems in line with C conventions? Generally a 0 return code means success.
- wruza 4y agoWith int statuses, not with bools. It’s just a twisted logic in return value you have to deal with in your head. “If checked operation has a status, then it failed.” - ok “If checked operation [is true], then it failed.” - wat
- SAI_Peregrinus 4y agoThe checked operations ask "did an error occur?". If it's false, then the check passed and no error occurred. If it's true, then the check indicated an error.
- masklinn 4y ago> With int statuses, not with bools Which C historically did not have, so int played that role. The function is the same, and the existing idioms remain.
- wruza 4y agoI find it strange to introduce real bools (which these macros return according to their official signatures) and then to assign them a meaning of a still-nonexistent but widely used C type. At least my C intuition stumbles upon that immediately, no matter how long I think about it. Ah, anyway, standard C/libc is basically a lost cause. It can’t get any worse, since you have to refer to a manual at every call to not step on a landmine.
- notfed 4y agoIsn't the return value just a carry bit?
- spc476 4y agoNot every CPU C runs on has a carry bit. MIPS, SPARC, RISC-V, all don't have the concept of a "carry bit."
- Dwedit 4y agoReplace memset with a macro, that's the C way.
- Kamq 4y ago> Finally, the checked arithmetic operations returning false on success That's what got you? C functions returning error flags (with zero meaning no error) isn't exactly new.