Pregunta

I have searched a lot and found a beautiful reference of https://en.wikipedia.org/wiki/C_standard_library different header files, but it doesn't say anything about the common functions they define. Is there any brief reference to commonly used C functions?

For example:

#include <getopt.h>
#include <event.h>
#include <libpq-fe.h>
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <pwd.h>
#include <grp.h>

..are headers which I see commonly on major c programs.. Can anyone explain what they do?

  • Nb : if i see a method int XXX(char *YYY) , how can i find in which header this method is defined ..

¿Fue útil?

Solución 2

There is no in-detail explanations of how everything work in standard C library I am aware of. I can not tell if there is any, but note that the implementation is platform-dependent. Thus, you will need many explanations.

It would be better for you to take a look at the documentation and the source of the libc you are using. For instance, for glibc it can be found here: docs, source.

As of the headers you have mentioned, it really is not standard in C (except stdio.h), though commonly used in linux. For instance, getopt.h lets you use functions for command line options traversal. It is quite easy to google what each header is related to. There is no header-meaning relation in one place for every header you will see.

Finding out which header contains a function is usually done by googling. Yes, again. But there are at least two other ways to find it out. First, if you use an IDE, it can let you 'go to declaration' of a function, which will effectively find the header file. Second, you can grep through all /usr/include/ files (or wherever your header files are stored) and find where the function is declared.

Also note that where a function is declared in a header does not tell you where the function is implemented. For instance, most (if not all) functions from standard library are implemented in glibc (or ms c runtime).

Otros consejos

See here for what's standard C:

http://port70.net/~nsz/c/c11/n1570.html#7

And here for what's standard POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/contents.html

As for how to find where a given function is declared, lookup the function here:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/contents.html

and the correct header will be shown in the synopsis text. Your own system's manual (e.g. man pages on *nix) will probably also contain this information, but around 5% of the time they're wrong, so it's best to look to the standards for the authoritative answer.

Actually if you look at your beautiful reference, you can click most of the include files and find there the list functions they define.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top