This is probably just an inconsistency of notation at cplusplus.com, but is there a difference between "long int" and "long" types in C++? cplusplus.com says that abs takes inputs of types "int" and "long", whereas labs uses "long int". I assume that this is basically a typo. If so, then is the only difference between abs and labs that labs is guaranteed to return a long?
There is no difference between long and long int.
The reason we have abs(long) and labs(long) (while both are equivalent) is that labs() is a remnant of the C library. C doesn't have function overloading, so function abs() can only take one type (int) and the long one has to be called differently, hence labs.
They are the same. Similar to "unsigned" and "unsigned int". Yes, in C++ there's an overload for abs() that takes a long argument. labs() is necessary for C programmers, they can only use the abs() function that takes an int. The C language doesn't support function overloading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With