What actually happened in following program, I have defined an empty array int arr[]; in code and with the GCC compiler, but the compiler doesn't give an error. It's successfully worked.
#include <stdio.h>
#include <stdlib.h>
typedef struct st
{
int i;
int arr[];
}ST,*ptr;
int main()
{
ST s1;
ptr p1= (ptr)malloc(sizeof(ST)+4*sizeof(int));
p1->i=10;
p1->arr[0]=1;
p1->arr[3] = 1;
printf("%d\n",p1->arr[3]);
printf("%ld\n", sizeof(s1));
}
C language not allowed undefined array length. but GCC compiler allowed. Why?
Just curious, what actually happens?
mallocand don't hide pointers withtypedefs