This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to type-pun and why


Andrew Haley <aph@redhat.com> writes:

>It's a gcc extension to ISO C.  

I only found "union casts" among the relevant extensions, but perhaps they
imply that the union trick work? (I'm reluctant to use union casts as they
are illegal outside gcc, but the "union trick" seems to be customary.)

It is tempting to abbreviate the union trick by using pointers, like:

  double d = something;
  uint64_t x = ((union { double d; uint64_t x; } *)&d)->x;

which _seems_ to work - but this is purely anecdotal evidence.
Would this also be guaranteed by the same gcc extension?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]