Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Conor S. <bor...@ya...> - 2009-03-05 08:00:25
|
The point more is that just because it works some of the time as an artefact of a "correct" implementation (on most platforms, ints and floats being the same size etc), it doesn't mean that it will work everytime (and it isn't portable). One of the more important points is that (for example) in C++98 compilers, there is no guarantee on the number of bits for most of the integral data types other than a minimal possible size and representable range. http://en.wikibooks.org/wiki/C%2B%2B_Programming/Data_Types_Reference Cheers, Conor ________________________________ From: Jeff Russell <je...@8m...> To: Game Development Algorithms <gda...@li...> Sent: Thursday, 5 March, 2009 3:37:02 PM Subject: Re: [Algorithms] How to get 3dvector largest coordinate index? yea i was gonna say, use of unions to reinterpret types is fairly widespread from what i can tell. if its wrong, a lot of software could have a lot of trouble with a "correct" compiler. or is this one of those cases where no compiler does it "right" anyway (at least by default) because so much existing code would break? the performance benefit of strict aliasing seems straightforward and hard to argue with. but it also seems like there should be *something* though. reinterpret_cast doesn't do the job either? seems odd that somehow the char* would be magical... jeff On Thu, Mar 5, 2009 at 12:23 AM, 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: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2008-December/056962.html 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 Stay connected to the people that matter most with a smarter inbox. Take a look http://au.docs.yahoo.com/mail/smarterinbox |