Menu

timercmp syntax error

jacob s
2021-01-28
2021-02-01
  • jacob s

    jacob s - 2021-01-28

    hi,

    #include <sys/time.h>
    
    int main() {
        struct timeval a = {0};
        struct timeval b = {0};
        return timercmp(&a, &b, <);
    }
    

    gives:

    cppcheck.c:6:29: error: syntax error: <) [syntaxError]
        return timercmp(&a, &b, <);
    

    this is, afaik, valid syntax.

    thanks, jacob

     
  • CHR

    CHR - 2021-01-30

    GCC chokes on it: https://ideone.com/yvgfUJ

     
  • jacob s

    jacob s - 2021-02-01

    hi,
    did you miss the include? works for me locally (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0), https://onlinegdb.com/B15ZmNBg
    https://godbolt.org/z/cPM4e4

    thanks, jacob

     
  • CHR

    CHR - 2021-02-01

    My bad, ideone.com seems to not have that header available.
    It looks like cppcheck doesn't pick up that timercmp is a macro. This works however:

    struct timeval {
      long tv_sec;
      long tv_usec;
    };
    
    #define timercmp(a, b, CMP)          \
      (((a)->tv_sec == (b)->tv_sec) ?    \
       ((a)->tv_usec CMP (b)->tv_usec) : \
       ((a)->tv_sec CMP (b)->tv_sec))
    
    int main() {
        struct timeval a = {0};
        struct timeval b = {0};
        return timercmp(&a, &b, <);
    }
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.