News for hackers. Stuff that matters.
Re:Constexpr-8cc: Compile-time C Compiler by zmodem on Friday November 18, 2016 @04:52PM (#12990385)
> the compiler guarantees to evaluate it at compile time

It doesn't guarantee that.

For example:

  static constexpr int fac(int x) { return x <= 1 ? 1 : x * fac(x - 1); }
  int f() {
    return fac(4); // May or may not be evaluated at run-time.
  }
  char arr[fac(4)]; // fac(4) is evaluated at compile-time.
Re:Constexpr-8cc: Compile-time C Compiler by JoshTriplett on Friday November 18, 2016 @06:59PM (#12991033)
I should have said, "guarantees that it can evaluate it at compile time if needed, such that you can use it where the compiler expects a compile-time constant expression". Yes, the compiler can choose to defer it until runtime in some cases.
Re:Constexpr-8cc: Compile-time C Compiler by euyyn on Friday November 18, 2016 @07:33PM (#12991188)
Can it be forced to be computed at compile-time, by static_assert'ing on the result of the computation?
Re:Constexpr-8cc: Compile-time C Compiler by gpderetta on Friday November 18, 2016 @07:42PM (#12991242)
Yes, among other things. As long as a program can't tell the difference (as per the as-if rule), the compiler is free to delay tjee evaluation till runtime.