Using timersub on Ubuntu Linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aaron.devore@gmail.com

    #1

    Using timersub on Ubuntu Linux

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

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

    Where <fileis 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(ti me_start);
    // some stuff runs
    gettimeofday(ti me_end);

    timersub(time_s tart, time_end, time_diff);

    What am I doing wrong?

    -Aaron
  • jacob navia

    #2
    Re: Using timersub on Ubuntu Linux

    aaron.devore@gm ail.com wrote:
    I'm trying to use the timersub macro on Ubuntu Linux. When I compile I
    get the error:
    >
    <file>.c:<lin e #>: warning: implicit declaration of function
    'timersub'
    >
    Where <fileis 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(ti me_start);
    // some stuff runs
    gettimeofday(ti me_end);
    >
    timersub(time_s tart, 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


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32

    Comment

    • Nate Eldredge

      #3
      Re: Using timersub on Ubuntu Linux

      jacob navia <jacob@nospam.c omwrites:
      aaron.devore@gm ail.com wrote:
      >I'm trying to use the timersub macro on Ubuntu Linux. When I compile I
      >get the error:
      >>
      ><file>.c:<li ne #>: warning: implicit declaration of function
      >'timersub'
      >>
      >Where <fileis 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.

      Comment

      • CBFalconer

        #4
        Re: Using timersub on Ubuntu Linux

        jacob navia wrote:
        aaron.devore@gm ail.com wrote:
        >
        >I'm trying to use the timersub macro on Ubuntu Linux. When I
        >compile I get the error:
        >
        .... snip ...
        >>
        >What am I doing wrong?
        >
        timersub is defined in time.h
        No such thing exists in standard C. Read section 7.23 of the C std.

        --
        [mail]: Chuck F (cbfalconer at maineline dot net)
        [page]: <http://cbfalconer.home .att.net>
        Try the download section.

        Comment

        • Antoninus Twink

          #5
          Re: Using timersub on Ubuntu Linux

          On 6 Oct 2008 at 1:21, CBFalconer wrote:
          jacob navia wrote:
          >aaron.devore@gm ail.com wrote:
          >>I'm trying to use the timersub macro on Ubuntu Linux.
          >>
          >timersub is defined in time.h
          >
          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.
          >>I'm trying to use the timersub macro on Ubuntu Linux.

          Comment

          • Kenny McCormack

            #6
            Re: Using timersub on Ubuntu Linux

            In article <48E9682A.CA649 E31@yahoo.com>,
            CBFalconer <cbfalconer@mai neline.netwrote :
            >jacob navia wrote:
            >aaron.devore@gm ail.com wrote:
            >>
            >>I'm trying to use the timersub macro on Ubuntu Linux. When I
            >>compile I get the error:
            >>
            >... snip ...
            >>>
            >>What am I doing wrong?
            >>
            >timersub is defined in time.h
            >
            >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.

            Comment

            Working...