简体   繁体   中英

Reference of all functions and constants in stdlib.h, stdio.h?

I'd like to look up all the functions, constants and types defined in C libraries: stdlib.h , stdio.h , ctype.h etc. So, when in C program I do: #include <stdlib.h> or #include <stdio.h> I'd like to know what are all the functions, constants and types I get with that?

What's the easiest way to do this locally on the computer ? I'm not so much interested in online references, especially if they're not official.

Is there a manpage that lists this for eg stdlib ? Does maybe GNU info program have docs for this? Or do I have to find an actual header file and look it up?

I'd prefer an universal approach, but if it differs from system to system I'm curious how to do that on both Mac and Linux?

Your terminology stdlib is not well-defined. There's a "Standard I/O Library" as part of the C Programming Language, and a stdlib.h header file.

For C identifiers, here's an overview for ISO C and POSIX identifiers .

Apart from that, you can look at the symbols in library files with

nm -AP /path/to/libfoobar.a

Update

To inspect a header in the form the compiler sees it, look at the result of preprocessing ( -E ):

$ gcc -E /usr/include/stdlib.h|less
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
[...]
typedef struct
  {
    int quot;
    int rem;
  } div_t;
typedef struct
  {
    long int quot;
    long int rem;
  } ldiv_t;
[...]
extern long int random (void) __attribute__ ((__nothrow__ , __leaf__));
[...]

When you include one of the standard C headers, at least three types of identifiers may be declared:

  • Identifiers specified by the C standard. The authoritative source for information on these is the C standard , plus documentation for the C implementation you are using.

  • Identifiers for extensions to the C language. For example, the headers may declare identifiers for POSIX functions. The headers might declare such identifiers only if you have requested them by defining certain preprocessor symbols before including the headers.

  • Identifiers for internal use of the C implementation. These identifiers commonly begin with an underscore followed by another underscore or a caputal letter, as the C standard reserves those. You can discover these identifiers by examining the actual header files in your C implementation, but you should not use them unless documentation for your implementation offers them for use.

Overall, if you want to know what C provides in the standard headers, you should read either the C standard (for authoritative information) or a good C textbook (for tutorial information). If you want to know what else is in the headers, there is a large variety of things that an implementation could put into the headers, so the way to find out what is there is to read the documentation for the implementation and/or to examine the header file and then find the documentation for the extra things it provides, such as the POSIX documentation .

You asked for sources on your computer. Your C implementation may come with documentation, and Unix includes documentation accessible via the man command. While you can examine the actual header files, it is important to understand the current contents of the headers do not constitute any promise about future behavior. Any internal identifiers may change in future versions, and the behavior of standard identifiers may change as permitted by the C standard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM