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]

Re: 8 bytes into 2 bytes fits ?


At 12:51 AM 9/9/98 z, you wrote:
>David C Binderman <dcb@pncl.co.uk> writes:
>
>> At 10:31 PM 9/2/98 -0300, you wrote:
>>> David C Binderman <dcb@pncl.co.uk> writes:
>>> 
>>>> surely pointers can only be cast to types big enough to hold them.
>>> 
>>> Casting a pointer (but not a pointer to member) to any integral type
>>> has always been allowed.  
>
>> Not in my experience of C++.
>
>You've got good experience, indeed.  :-)

Thanks.
I think it's so complex, that it'll keep me for at least another five 
years ;->

>[expr.reinterpret.cast]/4 says that a pointer can be explicitly
>converted to any integral type *large enough to hold it*.  

Which makes it compiler and machine dependent. I think it is safe territory
for egcs to error for trying to put a pointer into a char or a short,
(as my example code showed), but into an int (or long) is
more problematic.

>And I'm
>happy I can't find any other kind of cast that would allow such a
>lossy conversion.  Looks like the C++ standard fixed this C problem.
>Or wasn't that allowed not even in C?

The C part of egcs would be well advised to produce a warning for
these lossy conversions.

Regards
David C Binderman MSc BSc	+44 1293 534847		dcb@pncl.co.uk



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