<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I have a POD data overlay class template whose only member is a <font face="Courier">char[]</font>. It performs byte swapping and interfaces to a blob of data from the network.</div><div><br></div><div><font face="Courier">template< typename native ></font></div><div><font face="Courier">struct net_word {</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>char raw[ sizeof (native) ];</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font face="Courier">        </font></span></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space: pre;">        </span>operator native () const {</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>native ret;</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>COPY_OP( raw, raw + sizeof raw, reinterpret_cast< char * >( & ret ) );</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>return ret;</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font face="Courier">        </font></span></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>net_word & operator = ( native const & value ) {</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>COPY_OP( reinterpret_cast< char const * >( & value ), reinterpret_cast< char const * >( & value + 1 ), raw );</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>return * this;</font></div><div><font face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><font face="Courier">};</font></div><div><br></div><div>Supposing the implementation aligns such a class the same as a <font face="Courier">char</font>, is it safe to use it in the old-fashioned, unsafe C idiom:</div><div><br></div><div><font face="Courier">uint32_t datum = * (net_word< uint32_t > *) buf_ptr;</font></div><div><br></div><div>Is it any safer to jump through a little hoop with placement new?</div><div><br></div><div><font face="Courier">uint32_t datum = * new( buf_ptr ) net_word< uint32_t >;</font></div><div><br></div><div>Would any part of this mayhem be vulnerable to future semantic restrictions?</div><div><br></div><div>For the sake of argument, assume that the underlying memory came straight from malloc (and the NIC) and it’s never been assigned a dynamic type, or referenced in any way besides <font face="Courier">char *</font>.</div><div><br></div></body></html>