Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are standard library function names different between Windows and Linux?

I am porting a Windows library to Android (with the GNU Standard C++ Library option, libstdc++-v3) and there seem to be numerous naming differences between the VC and GNU libraries, e.g.:

  • _stricmp is called strcasecmp instead
  • _unlink is called unlink
  • _scalb is called scalbn
  • _finite is called isfinite
  • _isnan is called isnan
  • _itoa and itoa do not seem to exist in GNU C++
  • atoi does exist, but not atoi64

The documentation of both VC and GNU libraries implies that they implement "ISO" C++, for example I can get a few warnings out of VC2008 for not using "ISO C++" names, such as this one: "warning C4996: 'itoa': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa." Similarly GNU's manual says "The GNU Standard C++ Library v3 is an ongoing project to implement the ISO 14882 Standard C++ library".

So how do the libraries end up with these different names? How can I tell which names are more "standard"?

Also, is there an index of libstdc++-v3 anywhere, i.e. a simple list of all functions in the library? I can only find a manual and the "source documentation" which does not appear to offer a list of functions.

like image 901
Qwertie Avatar asked Mar 27 '12 19:03

Qwertie


People also ask

What is standard function library?

C Standard library functions or simply C Library functions are inbuilt functions in C programming. The prototype and data definitions of these functions are present in their respective header files. To use these functions we need to include the header file in our program.

What is c library in Linux?

The term "libc" is commonly used as a shorthand for the "standard C library", a library of standard functions that can be used by all C programs (and sometimes by programs in other languages). Because of some history (see below), use of the term "libc" to refer to the standard C library is somewhat ambiguous on Linux.

How many types of library function are there?

Library functions include standard input/output (stdio. h), string manipulation (string. h), math functions (math. h), and date and time functions (time.

Where are the C libraries in Linux?

The C standard library itself is stored in '/usr/lib/libc.


1 Answers

This has very little to do with the C++ standard library. It has more to do with C99 and POSIX.

  • strcasecmp is a POSIX function that libstdc++ happens to implement. msvcrt typically stays at arm's length from POSIX.
  • unlink is similar—it's a POSIX function.
  • scalbn is the name of the function in the C99 standard. MSVC doesn't support C99. However, scalbn is part of C++11, so I would expect it to show up in msvcrt eventually.
  • isfinite and isnan are both C99.
  • itoa is neither C99 nor POSIX. It's a strange beast that just shows up in the night.

I'll also point out what several others have pointed out: it's technically more correct to prefix any functions in the standard library that are actually non-standard with an underscore. That's the reason for the proliferation of underscores in msvcrt.

like image 52
John Calsbeek Avatar answered Sep 28 '22 06:09

John Calsbeek