Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > gcc -std=c99 fail to compile clock_gettime?

Reply
Thread Tools

gcc -std=c99 fail to compile clock_gettime?

 
 
Ethan
Guest
Posts: n/a
 
      11-13-2010
/* rtclock.c */
#include
<time.h>

int main
()
{
struct timespec
ts;
clock_gettime(CLOCK_REALTIME,
ts);

return
0;
}

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.)

 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      11-13-2010
On 2010-11-13, Ethan <> wrote:
> but why doesn't this compile with
> $> gcc -std=c99 -c -g rtclock.c


Because you just told it not to define any symbols that aren't part of
standard C. Such as POSIX features, or GNU features.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      11-13-2010
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc -std=c99 fail to compile clock_gettime? Ethan C++ 1 11-13-2010 09:37 AM
gcc -std=c99 fail to compile clock_gettime? Ethan C++ 2 11-13-2010 05:53 AM
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Template construction in old gcc 3.3.3 does not compile in gcc 3.4.4 eknecronzontas@yahoo.com C++ 5 09-17-2005 12:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57