0

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?

  • You mean how the actual header is defined/implemented or what the C standard states it should include? – UnholySheep May 23 '18 at 10:52
  • 1
    I would lookup via the headers. IMO a good site to look that up would be [C Standard Library headers on C++Reference](http://en.cppreference.com/w/c/header) – CannedMoose May 23 '18 at 10:56
  • 3
    Questions asking where to find off-site resources are off-topic. That being said, the easiest is to Google "C11 draft", download the pdf, then go read Appendix B - Library Summary. – Lundin May 23 '18 at 10:57
  • Updated the question to indicate I'd much prefer a way to do this locally, not using an off-site resource. –  May 23 '18 at 11:37
  • What exact macros, constants, variables, types and functions are declared when you `#include ` is irrelevant -- you are allowed to use only those which the standard says you are allowed to use. The final draft of the standard is [available on-line](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf). (The actual standard costs money, but it is the exact same as the final draft.) You would normally be more interested to find out what header to include to get a specific function or macro, rather than to find out what functions or macros you get from a specific header. – AlexP May 23 '18 at 12:32
  • Look up the C Standard (N1570), this is more reliable than any other info – M.M May 23 '18 at 14:26

2 Answers2

1

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__));
[...]
Jens
  • 69,818
  • 15
  • 125
  • 179
  • Sorry for the confusion. I updated the question to clarify `stdlib`: what are all the functions, types and constants I get with `#include `? –  May 23 '18 at 11:38
  • 1
    @BrunoSutic There is no simple answer to this since it depends on the particular *Standard* and *Feature Test Macros* you specify when compiling. I.e. `gcc -std=c89` will make a different set available than `gcc -std=c11 -D_POSIX_SOURCE`. – Jens May 23 '18 at 14:03
  • @BrunoSutic That said, you can look at the preprocessing result to see what you get in all its glory. Assuming gcc on a unixoid system, use `gcc -E /usr/include/stdlib.h`. – Jens May 23 '18 at 14:07
1

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.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312