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


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

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

From MarioCPPP <NoliMihiFrangereMentulam@libero.it>
Newsgroups comp.lang.c++
Subject Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2)
Date 2023-03-03 13:22 +0100
Organization A noiseless patient Spider
Message-ID <ttsopt$kklh$1@dont-email.me> (permalink)
References <ttqilb$b9c8$1@dont-email.me> <ttqn9h$bpn9$1@dont-email.me> <ttr8f7$df6l$3@dont-email.me> <87ilfimysr.fsf@nosuchdomain.example.com>

Show all headers | View raw


On 03/03/23 02:03, Keith Thompson wrote:
> 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'll follow your advice and restudy this keyword.
Simply put I just believed that it was a cast made at 
compile time plus some "checks" it was a legit cast. But 
maybe this is wrong and I will restudy it !
Reinterpret_cast was new to me so I have to start from zero.
Tnx

> 
>> 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.

it is true for types used by QTcreator that has "explicit" 
fixed byte-width types for 1,2,4,8 bytes.
They are likely some typedefs defined in math.h

> 
> [...]
> 

-- 
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
MarioCPPP

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