- 论坛徽章:
- 0
|
查了一下,属于gcc的extension,也是c99标准的一部分
Variable-length automatic arrays are allowed in ISO C99, and as an
extension GCC accepts them in C89 mode and in C++. (However, GCC's
implementation of variable-length arrays does not yet conform in detail
to the ISO C99 standard.) These arrays are declared like any other
automatic arrays, but with a length that is not a constant expression.
The storage is allocated at the point of declaration and deallocated
when the brace-level is exited. For example:
FILE *
concat_fopen (char *s1, char *s2, char *mode)
{
char str[strlen (s1) + strlen (s2) + 1];
strcpy (str, s1);
strcat (str, s2);
return fopen (str, mode);
}
Jumping or breaking out of the scope of the array name deallocates the
storage. Jumping into the scope is not allowed; you get an error
message for it.
info gcc -> C Extension -> Arrays of Variable Length
自己慢慢看吧 |
|