C/C++ hasn't been my primary programming language in recent years and the strict aliasing issue has evaded me. I not sure if I understood it correctly. There are plenty of standard C functions which have void * parameters, such as memset, memcpy, read, write, etc. Does the strict aliasing rule mean the code below is not valid any more?
typedef struct {
int a;
char b;
} my_struct;
my_struct foo;
my_struct bar;
char buffer[sizeof(my_struct)];
foo.a = 42;
foo.b = 'a';
memcpy ((void *)buffer, (const void *)&foo, sizeof(my_struct));
memcpy ((void *)&bar, (const void *)buffer, sizeof(my_struct));
If the code above is valid, is there then something fundamentally wrong with the code below?
void sendAnything(const byte *value, unsigned int size)
{
for (unsigned int i = 0; i < size; i++)
Serial.write(*value++);
}
sendAnything((const byte *)&MyInt, sizeof(MyInt));
These were meant to be sincere questions, not intention to reignite the argument
edit: typos