Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Jason H. <jas...@di...> - 2009-03-07 03:56:37
|
So, how about a "standard friendly" version of Pal-Kristian's template from a few days ago: template<typename T, typename U> static T bit_cast(const U val) { union { U u; T t; } bits = { val }, secondBits; secondBits = bits; return secondBits.t; } float x = 3.1415926f; uint32 asUint = bit_cast<uint32>(x); Wouldn't this satisfy the standard? There's no situation when secondBits is accessed as two types, only as a union. JH Gino van den Bergen wrote: > My bad. It's the C99 standard, not the C++98 standard. > > "The following are unspecified: ... The value of a union member other > than the last one stored into (6.2.6.1)." > > liam mail wrote: > >> 2009/3/6 Gino van den Bergen <gin...@gm... >> <mailto:gin...@gm...>> >> >> Aliasing is having multiple references to the same memory location. >> >> >> >> "Call me reckless but I just do not believe that >> strict-aliasing on union fields will be exploited by a C++ >> compiler any >> time soon." >> >> Thank you I know what aliasing is, but as I said I do not see what >> this has to do with your comment as the standard guarantees the same >> space is in use. >> >> >> According to the C++ standard a compiler would be allowed to fetch >> pun.i >> before pun.f has been written >> >> >> >> and the result would contain garbage >> instead of the bit-representation of x. >> >> >> Would you mind quoting or pointing me to the part of the standard >> which implies this. >> >> Liam >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise >> -Strategies to boost innovation and cut costs with open source participation >> -Receive a $600 discount off the registration fee with the source code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> GDAlgorithms-list mailing list >> GDA...@li... >> https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list >> Archives: >> http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list >> > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > > > |