As I understand it, when we define an array like const char argv[SIZE];
"SIZE" must be a number which is known at compile time.
But recently I read AOSP code, and found this: http://androidxref.com/5.1.1_r6/xref/system/netd/server/NetdConstants.cpp#70
static int execIptables(IptablesTarget target, bool silent, va_list args) {
/* Read arguments from incoming va_list; we expect the list to be NULL terminated. */
std::list<const char*> argsList;
argsList.push_back(NULL);
const char* arg;
do {
arg = va_arg(args, const char *);
argsList.push_back(arg);
} while (arg);
int i = 0;
const char* argv[argsList.size()];
...
It seems that const char* argv[argsList.size()];
uses a size which is only known at runtime. Is this because this array is defined in a function which will allocate the array in the stack or because the compiler can figure out what the size is at compile time?