2

I have a little problem with my std::chrono.

Depending of G++ version some key words change (monotonic_clock/steady_clock).

I would like to do something like this: (pseudo-code)

If G++-version < 4.6
  Use this code
Else
  Use this one

I couldn't find any information on Google, maybe I don't have the good keywords.

  • 1
    Google: "gcc version macro" chances are within the first two or three results you will get the gcc manual page where the predefined macros are explained, including how to get the major/minor versions of the compiler. Also note that you will need to add a different alternative for versions of gcc without `std::chrono` at all – David Rodríguez - dribeas May 23 '13 at 11:50
  • @DavidRodríguez-dribeas Thanks I was missing the 'macro' thing. Maybe you can post an answer in order I can validate it? For people researching about this. –  May 23 '13 at 11:51

1 Answers1

3

Based on the documentation provided here, you could do it this way:

#if __GNUC__ > 4 || \
    (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || \
        (__GNUC_MINOR__ == 6 && \
            __GNUC_PATCHLEVEL__ >= 0)))
    // Greater than or equal to 4.6.0
#else
    // Less than 4.6.0
#endif
Andy Prowl
  • 124,023
  • 23
  • 387
  • 451