Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Charles N. <cha...@gm...> - 2009-03-05 18:49:59
|
On Wed, Mar 4, 2009 at 10:23 PM, Matt J <mjo...@gm...> wrote: > > Well, I guess it depends on what standard you use (so many to choose from). > But like I mentioned before in the latest C99 TC3 standard it adds a clause > that says it is okay to do "type punning" through a union. Here is an FFMPEG > post that discusses it in detail: > This C99 TC3 note you keep quoting doesn't guarantee that it will always work, though, right? The last sentence in the note reads: "This might be a trap representation." To me that means that you can't just trust it to always work, it might blow up and is compiler-and-platform specific. I don't think you have the blessing of the C99 standards committee to cast-through-union whenever you want and they promise it will be ok. Plus I don't believe it's part of the C++03 standard, so even if gcc implements it there's no guarantee that MSVC will (in C++ mode), if they ever start exploiting TSAA-based optimizations by default. (they don't support C99 yet either). -charles Finally, even CERT thinks its okay: > > > https://www.securecoding.cert.org/confluence/download/attachments/26017980/SD+West+Dangerous+Optimizations.pdf?version=1 > > See page 75. Which was written in 2009. I understand that is an argument > based on an appeal to authority, but the assumption here is these four guys > that wrote this understand good coding practices better than most. GCC holds > C++ code to C99 standards, from what I read. So.... code that tried to > optimize unions would be non-conforming not to mention break tons of legacy > code in C and C++ > > >> >> > if cast-through-union violates the standard, then why are unions in >> > the language? isn't storing bytes and interpreting them as different >> > types what unions are for? >> >> No, that's not what unions are for. Unions are there to allow >> you to store different type data in the same memory location >> at DIFFERENT (nonoverlapping) TIMES. >> >> Standard-violating aliasing is when you have different type >> data in the same memory location at the SAME TIME. >> >> The standard disallows same-time different-type aliasing, >> because disallowing it allows for a lot of optimization >> opportunities. This is a GOOD THING -- except programmers >> need to learn to write standard-conforming code (which is >> also a GOOD THING). >> >> >> > > > ------------------------------------------------------------------------------ > 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 > |