tags:

views:

98

answers:

4

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?

A: 

long and long int are equivalent and interchangeable.

Bill
+6  A: 

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.

jpalecek
thanks. this solves it.
flies
+1  A: 

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.

Hans Passant
+1  A: 

long int is the same type as long. abs and labs are from C where there is no function overloading. long abs(long) is the same as long labs(long) in C++. For example, GCC has

inline long abs(long __i) { return labs(__i); }
Philipp