Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2)
Date: Sun, 05 Mar 2023 08:20:28 -0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <86zg8r890z.fsf@linuxsc.com>
References:
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader01.eternal-september.org; posting-host="7cbd56fc705b753f03c17ec3c53cb2bb"; logging-data="1467580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mZu0W7O9BUgLNlgkpDOZ/h6l3hPE/MQo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qfBE9mSHxolrQfsNgtE0WPI+NIM= sha1:kscGgZCCDcbbGQNEGkMc03z5wKM=
Xref: csiph.com comp.lang.c++:89445
Bo Persson writes:
> On 2023-03-02 at 17:27, MarioCPPP wrote:
>
>> On 02/03/23 17:25, MarioCPPP wrote:
>>
>>> I have this situation :
>>>
>>> int32_t * Pointer32; // is a 4 byte signed int
>>> int8_t * Pointer8; // is a "signed char"
>>> // pointer allegedly "unaligned".
>>>
>>> Pointer32 = new int32_t [10];
>>> // supposedly ALIGNED a multiple of four byte addresses
>>>
>>> Pointer8 = static_cast (Pointer32);
>>
>> Using an old style casts deserves just a warning ...
>> Pointer8 = (int8_t *) (Pointer32);
>>
>> but it seems an ugly solution for a problem still not understood, so
>> please explain me the "ratio" of the error with static_cast
>
> The problem isn't about alignment, but that the code uses a pointer to
> signed char. The standard allows inspecting bytes as unsigned char,
> but has no special allowance for signed char.
This comment is at best misleading. A static_cast to (unsigned char *)
isn't allowed any more than a static_cast to (int8_t *) is.