| 1 | #include <stdlib.h> |
|---|---|
| 2 | #include <string.h> |
| 3 | |
| 4 | struct WithFlexChar { |
| 5 | int member; |
| 6 | char flexible[]; |
| 7 | }; |
| 8 | |
| 9 | struct WithFlexSChar { |
| 10 | int member; |
| 11 | signed char flexible[]; |
| 12 | }; |
| 13 | |
| 14 | struct WithFlexUChar { |
| 15 | int member; |
| 16 | unsigned char flexible[]; |
| 17 | }; |
| 18 | |
| 19 | #define CONTENTS "contents" |
| 20 | |
| 21 | int main() { |
| 22 | struct WithFlexChar *c = |
| 23 | (struct WithFlexChar *)malloc(size: sizeof(int) + sizeof(CONTENTS)); |
| 24 | c->member = 1; |
| 25 | strcpy(dest: c->flexible, CONTENTS); |
| 26 | |
| 27 | struct WithFlexSChar *sc = |
| 28 | (struct WithFlexSChar *)malloc(size: sizeof(int) + sizeof(CONTENTS)); |
| 29 | sc->member = 1; |
| 30 | strcpy(dest: (char *)sc->flexible, CONTENTS); |
| 31 | |
| 32 | struct WithFlexUChar *uc = |
| 33 | (struct WithFlexUChar *)malloc(size: sizeof(int) + sizeof(CONTENTS)); |
| 34 | uc->member = 1; |
| 35 | strcpy(dest: (char *)uc->flexible, CONTENTS); |
| 36 | return 0; // break here |
| 37 | } |
| 38 |
