gcc -std=c99 fail to compile clock_gettime?

E

Ethan

/* 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.)
 
M

Marc

Ethan said:
/* rtclock.c */
#include <time.h>
int main ()
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, ts);

insert '&' before '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

Did you notice something strange about posting a question about C99 in a
newsgroup called c++?

Did you read the manpage for clock_gettime? (hint: -D_XOPEN_SOURCE=500)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top