static and reinterpret casting - defined behavior?

can I safely static_cast the message to header

No. Such static cast is ill formed. Similar reinterpret cast would be well defined though... As long as your stated preconditions are true. If you assume them wrongly, then behaviour of the program is undefined.

As pointed out in a comment, your code example static casts header pointer to a header pointer which is of course well defined, but not what you asked about.

and reinterpret_cast the header pointer to a message pointer?

Yes.

Tags:

C++