Ethan <> writes:
> /* rtclock.c */
> #include <time.h>
>
> int main ()
> {
> struct timespec ts;
> clock_gettime(CLOCK_REALTIME, ts);
>
> return 0;
> }
I've taken the liberty of reformatting your code for legibility.
> gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
>
> it compiles with
> $> gcc -c -g rtclock.c
>
> but why doesn't this compile with
> $> gcc -std=c99 -c -g rtclock.c
> rtclock.c: In function ‘main’:
> rtclock.c:5: error: storage size of ‘ts’ isn’t known
> rtclock.c:6: warning: implicit declaration of function ‘clock_gettime’
> rtclock.c:6: error: ‘CLOCK_REALTIME’ undeclared (first use in this
> function)
> rtclock.c:6: error: (Each undeclared identifier is reported only once
> rtclock.c:6: error: for each function it appears in.)
Probably because the standard C version of <time.h> doesn't declare
any of those identifiers, and in a conforming C implementation
it may not do so. I might have expected it to be accepted if
you don't specify "-pedantic", but gcc's behavior is conforming.
Consult the gcc documentation for more information.
Experiment shows that most of the error messages go away if you use
"-std=gnu99" rather than "-std=c99". (Finding the one remaining
error is left as an exercise.)
I see that the man page for clock_gettime refers to
feature_test_macros(7); you might want to look into that as well.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"