I know I can do new char[n]
to create an array of n
chars. This works even when n
is not a compile time constant.
But lets say
You can also use the "Length 1 Array" trick. This is in C:
struct Test {
size_t size;
char a[1];
}
int want_len = 2039;
struct Test *test = malloc(sizeof(struct Test) + (want_len - 1));
test->size = want_len;
GCC also supports "0 length" arrays for exactly this purpose: http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html