My understanding of strict aliasing is that we cannot (with few exceptions like char*) use two different types of pointers to access/dereference the same region of memory. I have a char buffer and a pointer to a struct Foo, and i want to "save" this pointer into the buffer so that elsewhere I just retrieve the pointer and use it. Like this:
Foo* f =//pointer to some real Foo object
char buf[N];
memcpy(buf, &f, sizeof(Foo*));
then later:
Foo* f2 = *(Foo**) &buf;
f2->bla;
This breaks aliasing as pointed out below because buf is an array of characters and we treat it as a Foo** and dereference that. Is there a way to get my Foo object through with the pointer only through buf or do I have to copy all of Foo into the buffer?