Advertisement
STANAANDREY

dyn struct prop

Dec 10th, 2022 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5.   int x, y;
  6.   char name[30];
  7. } Entity;
  8.  
  9. typedef struct {
  10.   int num;
  11.   Entity data[];
  12. } flexArrayStruct;
  13.  
  14. void func() {
  15.   /* Space is allocated for the struct */
  16.   flexArrayStruct *structP= (flexArrayStruct *)malloc(sizeof(flexArrayStruct) + sizeof(Entity));
  17.  
  18.   structP->num = 1;
  19. }
  20.  
  21. int main(void) {
  22.   func();
  23.   return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement