Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Matt J <mjo...@gm...> - 2009-03-05 06:23:35
|
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). > > > |