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: subreg question



On Thursday, December 13, 2001, at 10:16 AM, Aldy Hernandez wrote:

>>>>>> "Dale" == Dale Johannesen <dalej@apple.com> writes:
>
>> What cases of subreg are supposed to be handled exactly?
>> double x(float y) {
>>      double z;
>>      *((float *)&z) = y;     <-- boo!
>>      return z;  }
>
> i believe this is invalid code, hence implementation dependent.  You
> can't access an lvalue as a different type as it was declared.

I don't see why not.  (C89) 3.3.4 says the cast might produce an invalid
pointer if it's not aligned properly, which is not the case here.
Other than that I don't find any relevant restriction in the standard.
What did you have in mind?
(FWIW, gcc doesn't warn about this even with -pedantic.)

> Try unions.

Unions don't create the subreg.

>> The original case involved Altivec vectors, which as you recall are
>> 16 bytes:
>
>>      vector signed char v;
>>      int i;
>>      *((int *)&v) = i;
>
> ditto here.  I don't think you can do this.-- well, should.

There is existing user code that does it.  Not that that should affect
what FSF gcc does necessarily, but I'm not convinced there's any reason
to bar this.


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