Using timersub on Ubuntu Linux

A

aaron.devore

I'm trying to use the timersub macro on Ubuntu Linux. When I compile I
get the error:

<file>.c:<line #>: warning: implicit declaration of function
'timersub'

Where <file> is the file name and <line #> is the line number. I take
that to mean I that the timersub macro hasn't been #included. My code
looks about like this:

#include <time.h>
#include <sys/time.h>

struct timeval *time_start, *time_end, *time_diff;

gettimeofday(time_start);
// some stuff runs
gettimeofday(time_end);

timersub(time_start, time_end, time_diff);

What am I doing wrong?

-Aaron
 
J

jacob navia

I'm trying to use the timersub macro on Ubuntu Linux. When I compile I
get the error:

<file>.c:<line #>: warning: implicit declaration of function
'timersub'

Where <file> is the file name and <line #> is the line number. I take
that to mean I that the timersub macro hasn't been #included. My code
looks about like this:

#include <time.h>
#include <sys/time.h>

struct timeval *time_start, *time_end, *time_diff;

gettimeofday(time_start);
// some stuff runs
gettimeofday(time_end);

timersub(time_start, time_end, time_diff);

What am I doing wrong?

-Aaron

timersub is defined in time.h

# define timersub(a, b, result) \
do {
\
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;
\
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;
\
if ((result)->tv_usec < 0) {
\
--(result)->tv_sec;
\
(result)->tv_usec += 1000000;
\
}
\
} while (0)


BUT
this macro will be defined ONLY if the preprocessor symbol
__USE_BSD
is defined.

Probably you have to convince gcc to define that symbol.
Read the documentation for that.

In ANY case if the definition isn't seen the link will not work since
timersub is a compiler macro and will be absent from the libraries
 
N

Nate Eldredge

jacob navia said:
I'm trying to use the timersub macro on Ubuntu Linux. When I compile I
get the error:

<file>.c:<line #>: warning: implicit declaration of function
'timersub'

Where <file> is the file name and <line #> is the line number. I take
that to mean I that the timersub macro hasn't been #included. My code
looks about like this:
[snip]

timersub is defined in time.h [snip]

BUT
this macro will be defined ONLY if the preprocessor symbol
__USE_BSD
is defined.

Probably you have to convince gcc to define that symbol.
Read the documentation for that.

Specifically, the section of the glibc manual entitled "Feature test
macros". It appears you are supposed to define the macro _BSD_SOURCE
and link with -lbsd_compat.
 
A

Antoninus Twink

No such thing exists in standard C. Read section 7.23 of the C std.

The OP isn't using "standard C". He's just using C. Read the subject
line, or the words you quoted above - surely even someone in your
advanced stage of senility can't forget words two lines previously?
Here they are again: take note and stop being such an idiot.
 
K

Kenny McCormack

No such thing exists in standard C. Read section 7.23 of the C std.

No such thing exists in the Bible either. I suspect both of these
observations are of equal value to the OP.
 

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,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top