Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #89402

Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2)

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2)
Date 2023-03-02 17:03 -0800
Organization None to speak of
Message-ID <87ilfimysr.fsf@nosuchdomain.example.com> (permalink)
References <ttqilb$b9c8$1@dont-email.me> <ttqn9h$bpn9$1@dont-email.me> <ttr8f7$df6l$3@dont-email.me>

Show all headers | View raw


MarioCPPP <NoliMihiFrangereMentulam@libero.it> writes:
> On 02/03/23 18:44, Andrey Tarasevich wrote:
>> On 03/02/23 8:25 AM, 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 <int8_t *> (Pointer32);
>>>
>>> ERROR : STATIC CAST FROM int * to signed char * IS NOT ALLOWED.
>>>
>>> I am asking why that ?
>>>
>>> I mean, the reverse, maybe with a warning, seems weird (at best
>>> very slow).
>>>
>>> But casting a MORE RESTRICTIVELY ALIGNED pointer to one LESS
>>> RESTRICTIVELY ALIGNED seems pretty reasonable. Why not ?
>> "Aligned"? Why are you even mentioning alignment in this 
>> context? What does it have to do with anything?
>
> because pointers should grant that pointed integral types pointed are
> accessible at correct memory addresses ... Am I wrong ?

What you appear to be wrong about is what "static_cast" means.

cppreference.com is not definitive, but it tends to be pretty good.

https://en.cppreference.com/w/cpp/language/static_cast

> I knew that "short" are aligned at addresses multiple of 2, "int" are
> aligned at addresses multiple of 4, "long" are aligned at addresses
> multiple of 8 bytes.

If you mean that you know that's the case for the implementation you're
using, that's fine.  If you mean that it's true in general, it isn't.
Different implementations can and do have different sizes and alignments
for integer types.

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

strange error (QT Creator 4.12.2, based on QT creator 5.14.2) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-02 17:25 +0100
  Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-02 17:27 +0100
    Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Bo Persson <bo@bo-persson.se> - 2023-03-02 17:44 +0100
      Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:20 -0800
  Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-03-02 09:44 -0800
    Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-02 23:37 +0100
      Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-03-02 17:03 -0800
        Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-03 13:22 +0100
          Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-03-03 09:29 -0800
            Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-04 22:53 +0100

csiph-web