3 ms·
But you want if( !canSafelyAdd(a,b)) return ERROR; c = a + b; To compile down to an add and a check of the overflow bit. For that, you need help from th
by Someone 12y ago
But you want
if( !canSafelyAdd(a,b)) return ERROR;
c = a + b;
To compile down to an add and a check of the overflow bit. For that, you need help from the compiler.
There are many examples where compilers special-case what is in a library. For example, compilers know they do not have to call strlen every time through this loop:
for(int i = 0; i < strlen(s); ++i)
- acqq 12y agoThe enough help you need is, in the implementation of the library function #if X86 #if GCC etc and then the assembly for each case, otherwise the slow but standard implementation. And that's one file, the code never to be directly used but by function name. It's already done this way in the current libraries for a lot processor specific stuff.