This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 8 bytes into 2 bytes fits ?
- To: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Subject: Re: 8 bytes into 2 bytes fits ?
- From: David C Binderman <dcb at pncl dot co dot uk>
- Date: Thu, 10 Sep 1998 19:29:12 +0100 (BST)
- Cc: egcs at cygnus dot com
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