Compiling the NIST Time Client
Hello all.
I downloaded the source code for the NIST Time Client from ftp://time-a.nist.gov/pub/daytime and compiled it using make. I made the following changes to the source code to make it compile without errors but I want to verify here that I have not committed a blunder (though the program compiles and works properly).
I got:
samjnaa@linux:~/src/daytime> make nistime
cc -o tcp.o -c tcp_time_client.ctcp_time_client.c: In function ‘main’:
tcp_time_client.c:172: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:172: error: too few arguments to function ‘exit’ tcp_time_client.c:203: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:203: error: too few arguments to function ‘exit’ tcp_time_client.c:209: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:209: error: too few arguments to function ‘exit’ tcp_time_client.c:228: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:242: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:247: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:255: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:308: warning: incompatible implicit declaration of built-in function ‘exit’
tcp_time_client.c:310: warning: incompatible implicit declaration of built-in function ‘exit’
make: *** [tcp.o] Error 1
So I replaced all occurrences of:
exit(); with return;
exit(0); with return 0;
exit(1); with return 1;
after which I got a clean compile and the program seems to work fine.
Converting exit to return seems a harmless operation but ever since I came to Linux I am somewhat paranoid about hacking anything myself without guidance...
Thanks.
Signature · 7 lines
Tux #395953 resides at http://samvit.org playing with KDE 3.51 on SUSE Linux 10.0 $ date [] CCE +2006-02-17 W07-5 UTC+0530 - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 34 lines · Shriramana Sharma
I downloaded the source code for the NIST Time Client from ftp://time-a.nist.gov/pub/daytime and compiled it using make. I made the following changes to the source code to make it compile without errors but I want to verify here that I have not committed a blunder (though the program compiles and works properly).
I got:
samjnaa@linux:~/src/daytime> make nistime
cc -o tcp.o -ctcp_time_client.ctcp_time_client.c: In function -F¡main¢:-A tcp_time_client.c:172: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:172: error: too few arguments to function -F¡exit¢-A tcp_time_client.c:203: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:203: error: too few arguments to function -F¡exit¢-A tcp_time_client.c:209: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:209: error: too few arguments to function -F¡exit¢-A tcp_time_client.c:228: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:242: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:247: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:255: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:308: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
tcp_time_client.c:310: warning: incompatible implicit declaration of built-in function -F¡exit¢-A
make: *** [tcp.o] Error 1
Quoted 5 lines
So I replaced all occurrences of:
exit(); with return;
exit(0); with return 0;
exit(1); with return 1;
Wrong fix, although it will work so long as all of the calls are from within main().
The correct fix is to add "#include <stdlib.h>" to the top of the file.
The call to exit() needs to be changed to either exit(1) or exit(0), depending upon whether it indicates an error.
Signature · 5 lines
Glynn Clements <[email protected]> - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Shriramana Sharma
Hello all.
I downloaded the source code for the NIST Time Client from ftp://time-a.nist.gov/pub/daytime and compiled it using make. I made the following changes to the source code to make it compile without errors but I want to verify here that I have not committed a blunder (though the program compiles and works properly).
Quoted 7 lines
I got:
samjnaa@linux:~/src/daytime> make nistime
cc -o tcp.o -ctcp_time_client.ctcp_time_client.c: In function ‘main’:
tcp_time_client.c:172: warning: incompatible implicit declaration of built-in function ‘exit’
Is stdlib.h included ?
Quoted 1 line
tcp_time_client.c:172: error: too few arguments to function ‘exit’
<snip>
Quoted 5 lines
So I replaced all occurrences of:
exit(); with return;
exit(0); with return 0;
exit(1); with return 1;
exit() takes one argument. exit() is not the same as return. 'man 3 exit' for details.
RDB
Signature · 7 lines
Reuben D. Budiardja Dept. Physics and Astronomy University of Tennessee, Knoxville, TN - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Friday, 17 February 2006 18:33 samaye, Reuben D. Budiardja alekhiit:
Quoted 2 lines
exit()takes one argument.exit()is not the same as return. 'man 3 exit' for details.
All I can see is that exit mandatorily takes an argument whereas if return is not given an argument the return status is that of the last command executed in the function body.
Further, exit is a function whereas return is a statement, not that that really makes much of a difference (does it?).
Is there something else?
Signature · 3 lines
Tux #395953 resides at http://samvit.org playing with KDE 3.51 on SUSE Linux 10.0 $ date [] CCE +2006-02-18 W07-6 UTC+0530
Quoted 6 lines · Shriramana Sharma
Quoted 2 lines
exit()takes one argument.exit()is not the same as return. 'man 3 exit' for details.All I can see is that exit mandatorily takes an argument whereas if return is not given an argument the return status is that of the last command executed in the function body.
If the function returns a value (i.e. not "void"), return should have an argument. If it doesn't, and the compiler doesn't generate an error, the function's return value is undefined. For Linux/x86/gcc, it will be whatever happened to be in the EAX register at that point.
Linux/x86 uses the EAX register to return function results. If you do "return <expr>", gcc will put the value of <expr> into EAX then return. If you just do "return", it will return without storing anything in EAX, so the return value will be whatever happened to be in EAX at that point. If the EAX register hasn't been used since, it will be the return value from the last function call.
Quoted 2 lines
Further, exit is a function whereas return is a statement, not that that really makes much of a difference (does it?).
Yes; return and exit() are only equivalent inside main(). return returns from the current function, exit() terminates the program. If you return from main(), the program will terminate, so the two are equivalent in that particular case.
Signature · 1 line
Glynn Clements <[email protected]>
Quoted 11 lines · Shriramana Sharma
Friday, 17 February 2006 18:33 samaye, Reuben D. Budiardja alekhiit:
Quoted 2 lines
exit()takes one argument.exit()is not the same as return. 'man 3 exit' for details.All I can see is that exit mandatorily takes an argument whereas if return is not given an argument the return status is that of the last command executed in the function body.
Further, exit is a function whereas return is a statement, not that that really makes much of a difference (does it?).
return and exit(3) have completely different effects on program execution. While return simply returns from a function call, exit(3) does not return. If return is called from within main, the process is terminated with the given return code. If its called from within another function return causes the process to return control of execution to the function that called it in the first place. exit(3) causes the kernel to terminate the process sending SIGCHLD to the parent and allowing the parent to fetch the child's exit status with wait(2) or waitpid(2).
\Steve
--
Steve Graegert <[email protected]>
Software Consultant {C/C++ && Java && .NET}
Office: +49 9131 7123988
Mobile: +49 1520 9289212