https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91205
--- Comment #2 from Ricardo Ribalda <ricardo at ribalda dot com> ---
Hi Jakub
I can agree that I do not like the code style and I have already send a patch
for that.
On the other hand is a bit frustrating that mangling a bit the struct, or using
memcpy is enough to make it work.:
#include <string.h>
#include <stdio.h>
struct tftphdr {
short th_opcode; /* packet type */
union {
char tu_padding[3]; /* sizeof() compat */
char tu_data[0]; /* data or error string */
} __attribute__ ((__packed__)) th_u1;
} __attribute__ ((__packed__));
static char buf[512];
int main(int argc, char* argv[])
{
struct tftphdr *tp;
tp = (struct tftphdr *) buf;
strcpy(tp->th_u1.tu_data, "Hello world");
fprintf(stdout, "Code works %s!\n", tp->th_u1.tu_data);
return 0;
}