mercredi 25 janvier 2017

Why GCC does not evaluate constexpr at compile time?

As an example:

class something {
public:
  static constexpr int seconds(int hour, int min, int sec)
  { return hour*3600+min*60+sec; }
}

then:

printf("Look at the time: %d\n", something::seconds(10, 0, 0));

Will compile to a call to the function using g++, instead of putting a constant number. Why would g++ do that? There's no gain in it and kinda defeats the purpose of using constexpr instead of awful macros.

Aucun commentaire:

Enregistrer un commentaire