Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between "long" and "long int", abs & labs

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?

like image 677
flies Avatar asked Dec 06 '22 02:12

flies


2 Answers

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.

like image 56
jpalecek Avatar answered Dec 07 '22 15:12

jpalecek


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.

like image 41
Hans Passant Avatar answered Dec 07 '22 15:12

Hans Passant