c - How could my code compile correctly without necessary headers? -


I use functions (), exec () ...

but how to program

I use Ubuntu 10.04 with GCC version 4.4.3

  add #lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Int main () {pid_t pid; Printf ("before fork \ n"); Pid = fork (); If (pid == 0) {/ * child * / if (execvp ("./cpuid", NULL)) {printf ("Error \ n"); Exit (0); }} And {if (Wait (tap)! = -1) {printf ("OK \ n"); }} Return 0; }  

In the classic "ANSI" C, if you have a function without declaring it The caller behaves like the compiler, the function was completely declared for taking the functions of the temporary-fixed-unspecified number and returning int . So your code works like fork () and execvp () was declared:

  int fork (); Int execvp ();   

Since execvp () takes a certain number of arguments and returns int , this declaration is consistent. Fork () also takes a certain number of arguments, but return pid_t ; Although pid_t and int are similar on most Linux architectures, but this announcement is also consistently consistent.

The actual definitions of these functions are standard standard linked to the standard library, so the definition link is available on time and thus the code works.

In the form of Keith Thompson Notes, the C99 modification of the C language standard of the language standard, and compilers applied in C99 or C11 modes should issue at least one warning when explicitly declaring a function Without saying it.


Comments