Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not quite the same as default arguments in that default arguments are evaluated at run time, whereas array lengths for C++ (and not C) needs to be a compile time constant expression.

    #include <stdio.h>

    // "puts" makes "f" not constexpr.
    constexpr int f() { return puts("hello"); }

    // error: size of array 'argv' is not an integral constant-expression
    int main(int argc, char *argv[f()]) {}


As you point out, VLAs in C are evaluated at run time too, making it very similar to abusing default arguments.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: