ABS(A) and abs(int) ABS(A) and abs(int) xcode xcode

ABS(A) and abs(int)


abs() works on int, meaning abs(-10.123) would return 10, while ABS() is a macro from NSObjCRuntime.h which returns a value whose type is the type of the argument.


The ABS definition from NSObjCRuntime.h is :

#define ABS(a) ({typeof(a) _a = (a); _a < 0 ? -_a : _a; })

so it returns the value with the type of the argument.abs on the other hand has the protoype

int abs (int number)

so it returns a value of type int.


ABS() is most likely a macro, meaning it's a copy-pasta of some code into your application, whilst abs() is probably a function. In most situations, use the function, as it has no odd reprocussions should you include an assignment in there.