Unexpected results compiling a program containing kill(2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Compiling this program

   #include <signal.h>
   #include <unistd.h>

   int main(int argc, char *argv[]) {
     return kill(getpid(), SIGTERM);
   }

with

   gcc -std=c99 -g -Wall  -o tst tst.c

yields

   tst.c: In function `main':
   tst.c:5: warning: implicit declaration of function `kill'

No amount of fiddling with include files gets rid of the warning. Adding
the prototype

   int kill(pid_t pid, int sig);

before the declaration of main generates this error

   tst.c:4: parse error before "pid"

However, adding the prototype 

   int kill(); 

results in a clean compilation without any errors or warnings. (I get
the same results with "-std=c89".)

But, if I use -std=gnu89 or -std=gnu99 I get a clean compilation.

Could someone explain what's going on? Why does using different C
language standards affect a UNIX system call? Why is kill(2) incorrectly
defined (to my mind) when using the vanilla C standards, but is defined
correctly when using the GNU C extensions?

I must be missing something really obvious, because kill(2) has been in
Unix since time immemorial.

Many thanks.

--- Vladimir

P.S. Mark Horton's "Portable C Software" says that kill is "very portable
amount UNIX systems" although there are some different interpretations.
The C99 standard does not list kill. Both SVR4 and BSD 4.4 have kill,
but with SVR4 needing to include sys/types.h in addition to signal.h.

------------------------------------------------------------------------
Vladimir G. Ivanovic                        http://leonora.org/~vladimir
2770 Cowper St.                                         vladimir@acm.org
Palo Alto, CA 94306-2447                                 +1 650 678 8014



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux