This is the mail archive of the gcc@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: Fields, unions, and code quality


Andrew Haley wrote:
> Does using fields of auto variables of union type generate code that
> is less efficient than it would be using scalars?
> 
> That is, if in C++ I declare my variables as
> 
> foo()
> {
>   union
>   {
>     int n;
>   };
> 
>   ...
> }
> 
> as opposed to simply
> 
> foo()
> {
>   int n;
> 
>   ...
> }
> 
> would gcc generate inferior code? 

It depends.
:)

For the most part, they should generate the same code, due to SRA.
Even when SRA doesn't do it, the structure aliasing should take care of it.

If you have ridiculously large unions, however, neither will touch them.


--Dan


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