fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct test_flex_arr{
  4. size_t sz;
  5. struct {
  6. int i;
  7. const char *path;
  8. } info[];
  9. } tfa;
  10.  
  11. int main(void){
  12. size_t sz = 100;
  13. tfa *ptr = malloc(sizeof *ptr + sizeof ((*((tfa*) NULL)).info)[sz]);
  14. ptr->info[99].i = 10;
  15. printf("%d\n", ptr->info[99].i); //prints 10
  16. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
10