declaring a variable-length array as a global variable in C

A variable length array (i.e. an array sized with a runtime value) can’t be a global variable, because the expression you are using for the size must obviously be computed at compile time. It can only live on the stack. Presumably what you are getting is a static array with a size that depends on where in the code you are defining it (because you are redefining something it depends on).

Why can’t you just use a global pointer and realloc() to size it as needed?

Leave a Comment