3 ms·
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 compil
by omoikane 4y ago
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()]) {}
- MayeulC 4y agoAs you point out, VLAs in C are evaluated at run time too, making it very similar to abusing default arguments.