, ,
#include <stdio.h>
#define BAD_ABS(A) ((A)<0 ? (-(A)):(A))
int afunc(){
printf("afunc was called\n");
return 1;
}
int main(void){
int a;
a = BAD_ABS(afunc());
}
'afunc' , < 0 second, -A A.
NSObjCRuntime.h , , DIY , .
, ,
#include <stdio.h>
#include <stdlib.h>
int main(void){
short seeds[] = {1,2,3};
int i;
for(i=0;i<10000;i++) printf("%ld\n", BAD_ABS(jrand48(seeds)));
}
it has a 50-50 chance to return a negative number !!!
If, on the other hand, you want to use the stdlib abs () function, then you should warn that it will not work with long integers. In this case, you should use labs ().
source
share