Variable arrays are already supported in C99, but not supported in VC, but flexible arrays (special variable-length arrays) are supported.
What is a flexible array, how to use it. Please look at the code below.
#include <stdio.h>
#include <string.h>
#include <malloc.h>
///Flexible array////
*
The last element in the C99 is allowed to be an array of unknown size, which is called a flexible array member, and the
flexible array member must precede at least one other member.
* *
typedef struct _FLEX_ARRAY
{
int nlen;
Char szbuff[];//flexible array member
} Flex_array,*pflex_array;
int main ()
{
char szmsg[] = "This is a C programe.";
Structure body size equals 4
int stsize = sizeof (Pflex_array);//=sizeof (int)
//allocating memory
pflex_array Psta = (pflex_array) malloc (Stsize + 100*sizeof (char));
Ordinary members and flexible array members in a structure are assigned
Psta->nlen = strlen (szmsg);
memcpy (psta->szbuff,szmsg,psta->nlen+1);
Structure body size stsize still equals 4 Description: The flexible array is not actually a member of the structure body
stsize = sizeof (PSTA);
Freeing memory free
(PSTA);
return 0;
}