Re: Narrow To Wide To Narrow String Conversion With reinterpret_cast

From: Tom Widmer (tom_usenet_at_hotmail.com)
Date: 09/10/04


Date: Fri, 10 Sep 2004 12:59:23 +0100

On Sat, 04 Sep 2004 11:52:17 +0100, Alwyn <dt015a1979@mac.com.invalid>
wrote:

>In article <WdPKpELorZOBFw90@robinton.demon.co.uk>, Francis Glassborow
><francis@robinton.demon.co.uk> wrote:
>
>> In article <040920041116593048%dt015a1979@mac.com.invalid>, Alwyn
>> <dt015a1979@mac.com.invalid> writes
>> >In article <f+U4RuCG4YOBFwOp@robinton.demon.co.uk>, Francis Glassborow
>> ><francis@robinton.demon.co.uk> wrote:
>> >
>> >As I read it, if the alignment requirements of T2 are no stricter than
>> >those of T1, then you can dereference the pointer safely.
>>
>> Read the quote from the Standard again, slowly and carefully. What it
>> says is that the requirement for round trip ( T1* -> T2* -> T*) validity
>> is that the alignment requirements for T2* will not result in an
>> irreversable modification to the T1* value when you forcibly convert it
>> to a T2*. As long as information is not lost on the way out, you will be
>> able to return to where you started. That is all it says.
>
>What precisely was it that I said that you didn't agree with?

You said:
>As I read it, if the alignment requirements of T2 are no stricter than
>those of T1, then you can dereference the pointer safely.

That statement is ambiguous - you don't way which pointer you can
dereference safely. Do you mean the pointer cast to a different type,
or the pointer cast back to its original type? The former is
incorrect, the latter fine.

Tom



Relevant Pages

  • Re: gcc: Whats illegal about this ?
    ... from gcc 4.1.2 on this line... ... Evem before the very queasy integer to pointer cast. ... non-portable code when you need to. ... (The standard doesn't use the term "illegal". ...
    (comp.lang.c)
  • Re: gcc: Whats illegal about this ?
    ... Evem before the very queasy integer to pointer cast. ... The only conversion available is to a void*, ... void* back to the original form. ... As far as the standard is concerned, ...
    (comp.lang.c)