Question

if you read a standard header file probably you will observe some external function declaration. but i couldn't find the full body of function in headers of that header file. can anybody tell me where is the complete definition of mentioned function. this is an example: pthread.h header file

extern int pthread_create (pthread_t *__restrict __newthread,
               __const pthread_attr_t *__restrict __attr,
               void *(*__start_routine) (void *),
               void *__restrict __arg) __THROWNL __nonnull ((1, 3));

and if through definitions this function will link with library object file so is there anyway to find the body of function?

Was it helpful?

Solution

It may be unavailable to you. People are not required to provide source code with C headers. For example on Windows it is very common to build the definitions of functions into DLLs and not provide the source code to you. For example Microsoft considers the source code to most Windows internals confidential.

On Linux, the source code is generally available, but there is no easy way to map a given header to its source code.

Your linux distribution may have tools that help. The apt-get source command on Ubuntu and Debian and the yumdownloader --source command on RPM-based distributions can find the source associated with most system packages.

OTHER TIPS

First of all, get to know why you are #include-ing a header file. The main reason is that to declare the function prototype before the occurrence of actual definition. That's why the header files are included in the very beginning of the file so that the function declaration appears before the (possible) call to them from the function in the .c file.

Never ever think of defining a function (or variable either) in the header file. If accidentally you are including a header file twice, you'll successfully get a redefinition error. So, only the declarations are present in them.

The definition for the appropriate functions are most likely to be present in the libraries (shared or static) that you are going to link with your source to create the final binary. Search in the appropriate library code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top