below is the code
Code:
#include <stdio.h>
typedef struct _test{
int a;
int b;
char data[0];
}Test;
/****************************************************************************************
* this eample proved that the data part is not deleted while free!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**/
int main(int argc, char *argv[]){
Test *tt = malloc(sizeof(Test) + 8);
tt->a = 20;
tt->b = 20;
tt->data[4] = ',';
printf("before free, tt->a is %d, tt->b is %d, tt->data[4] is %c\n", tt->a, tt->b, tt->data[4]);
free(tt);
printf("after free, tt->a is %d, tt->b is %d, tt->data[4] is %c\n", tt->a, tt->b, tt->data[4]);
//free(tt->data);
//printf("after free the data part, tt->a is %d, tt->b is %d, tt->data[4] is %c\n", tt->a, tt->b, tt->data[4]);
}
and the display
Code:
before free, tt->a is 20, tt->b is 20, tt->data[4] is ,
after free, tt->a is 0, tt->b is 0, tt->data[4] is ,
so the data[] is not freed? how can I delete it ?