While reading Unix System Design by Maurice Bach I came across below code snippet.
#include < signal.h>
char *cp;
int callno;
main() {
char *sbrk();
extern catcher();
signal(SIGSEGV, catcher);
cp = sbrk(O);
printf("original brk value %u\n", cp);
for (;;)
*cp++ = 1;
}
catcher(signo) {
int signo;
callno++;
printf("caught sig %d %dth call at addr %u\n", signo, callno, cp);
sbrk(256);
signal(SIGSEGV, catcher);
}
I got confused with two statements within main method
char *sbrk();
extern catcher();
I understand how extern works and I also know what sbrk() does but I couldn't understand why have they written extern before catcher() and also why is char* written before sbrk() call?
I got compilation error on gcc-4.8.4 on Ubuntu when compiling this code but code compiles without any errors in Mac. Why is this happening?