* Compiling the NIST Time Client
@ 2006-02-17 2:30 Shriramana Sharma
2006-02-17 6:24 ` Glynn Clements
2006-02-17 13:03 ` Reuben D. Budiardja
0 siblings, 2 replies; 6+ messages in thread
From: Shriramana Sharma @ 2006-02-17 2:30 UTC (permalink / raw)
To: Linux C Programming List
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.c
tcp_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.
--
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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Compiling the NIST Time Client
2006-02-17 2:30 Compiling the NIST Time Client Shriramana Sharma
@ 2006-02-17 6:24 ` Glynn Clements
2006-02-17 13:03 ` Reuben D. Budiardja
1 sibling, 0 replies; 6+ messages in thread
From: Glynn Clements @ 2006-02-17 6:24 UTC (permalink / raw)
To: Shriramana Sharma; +Cc: Linux C Programming List
Shriramana Sharma wrote:
> 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.c
> tcp_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
>
> 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.
--
Glynn Clements <glynn@gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Compiling the NIST Time Client
2006-02-17 2:30 Compiling the NIST Time Client Shriramana Sharma
2006-02-17 6:24 ` Glynn Clements
@ 2006-02-17 13:03 ` Reuben D. Budiardja
2006-02-18 5:10 ` Shriramana Sharma
1 sibling, 1 reply; 6+ messages in thread
From: Reuben D. Budiardja @ 2006-02-17 13:03 UTC (permalink / raw)
To: Shriramana Sharma; +Cc: Linux C Programming List
On Thursday 16 February 2006 21:30, Shriramana Sharma wrote:
> 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.c
> tcp_time_client.c: In function ‘main’:
> tcp_time_client.c:172: warning: incompatible implicit declaration of
> built-in function ‘exit’
Is stdlib.h included ?
> tcp_time_client.c:172: error: too few arguments to function ‘exit’
<snip>
> 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
--
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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Compiling the NIST Time Client
2006-02-17 13:03 ` Reuben D. Budiardja
@ 2006-02-18 5:10 ` Shriramana Sharma
2006-02-18 10:20 ` Glynn Clements
2006-02-18 10:20 ` Steve Graegert
0 siblings, 2 replies; 6+ messages in thread
From: Shriramana Sharma @ 2006-02-18 5:10 UTC (permalink / raw)
To: Linux C Programming List
Friday, 17 February 2006 18:33 samaye, Reuben D. Budiardja alekhiit:
> 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?
--
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Compiling the NIST Time Client
2006-02-18 5:10 ` Shriramana Sharma
@ 2006-02-18 10:20 ` Glynn Clements
2006-02-18 10:20 ` Steve Graegert
1 sibling, 0 replies; 6+ messages in thread
From: Glynn Clements @ 2006-02-18 10:20 UTC (permalink / raw)
To: Shriramana Sharma; +Cc: Linux C Programming List
Shriramana Sharma wrote:
> > 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.
> 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.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Compiling the NIST Time Client
2006-02-18 5:10 ` Shriramana Sharma
2006-02-18 10:20 ` Glynn Clements
@ 2006-02-18 10:20 ` Steve Graegert
1 sibling, 0 replies; 6+ messages in thread
From: Steve Graegert @ 2006-02-18 10:20 UTC (permalink / raw)
To: linux-c-programming
On 2/18/06, Shriramana Sharma <samjnaa@gmail.com> wrote:
> Friday, 17 February 2006 18:33 samaye, Reuben D. Budiardja alekhiit:
>
> > 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 <graegerts@gmail.com>
Software Consultant {C/C++ && Java && .NET}
Office: +49 9131 7123988
Mobile: +49 1520 9289212
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-02-18 10:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-17 2:30 Compiling the NIST Time Client Shriramana Sharma
2006-02-17 6:24 ` Glynn Clements
2006-02-17 13:03 ` Reuben D. Budiardja
2006-02-18 5:10 ` Shriramana Sharma
2006-02-18 10:20 ` Glynn Clements
2006-02-18 10:20 ` Steve Graegert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).