Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/01/10 15:32
Read: times


 
#174759 - It was just a warning that union type casts are dangerous
Responding to: ???'s previous message
Maarten Brock said:
You're not? Then who/what is? Ah, you think if the code I write doesn't use it, noone uses it. Well those two moves in and out of the timer surely use it. And are they aware of endianness?

He is just saying that he isn't using the construct with a union because he knows that it may result in a huge nose bleed some steps down the road, when he may need to switch to another compiler.

Unions are notoriously dangerous when used as type conversion tools.

Not a language standard problem, since they where not added to the language for type conversion, but for alternative storage without need for using a generic pointer with type casting. Especially since a generic pointer to a byte array may not have the required alignment to allow it to be type cast and accessed.


List of 23 messages in thread
TopicAuthorDate
Unions and position of bytes            01/01/70 00:00      
   Syntax and strategy problem.            01/01/70 00:00      
      wow that was quick and excellent thanks            01/01/70 00:00      
      Works a treat            01/01/70 00:00      
   Note that this is heavily compiler-reliant            01/01/70 00:00      
      Code for transparency            01/01/70 00:00      
         Agreed - after bitter experience            01/01/70 00:00      
            Compiler Specific            01/01/70 00:00      
               How many compler brands/versions to test for?            01/01/70 00:00      
                  Create a Compiler header            01/01/70 00:00      
                     Didn't we talk about unions - your examples doesn't...            01/01/70 00:00      
                        Someone already wrote up a good way....            01/01/70 00:00      
                           Incomplete byte order. But pad is still dangerous            01/01/70 00:00      
                              why bother?            01/01/70 00:00      
                                 how would you know?            01/01/70 00:00      
                                    Exactly my point... you don't            01/01/70 00:00      
                                       Never give up on portability - just decide the amount            01/01/70 00:00      
               Yes, but            01/01/70 00:00      
               why bother?            01/01/70 00:00      
      unions and portability            01/01/70 00:00      
         OT: use TR0 = 0; TMR0 -= offset; TR0 = 1;            01/01/70 00:00      
         you're not?            01/01/70 00:00      
            It was just a warning that union type casts are dangerous            01/01/70 00:00      

Back to Subject List