This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Fields, unions, and code quality
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: Andrew Haley <aph at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 20 Jun 2006 11:37:19 -0400
- Subject: Re: Fields, unions, and code quality
- References: <17560.1066.877603.629385@dell.pink>
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