Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #89399
| 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-02 23:37 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <ttr8f7$df6l$3@dont-email.me> (permalink) |
| References | <ttqilb$b9c8$1@dont-email.me> <ttqn9h$bpn9$1@dont-email.me> |
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 ? 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. And the pointers should grant that Pointer [Offset] can be read/written from ram with just ONE SINGLE access and no masking of data. > > C++ is a strictly typed language and `int8_t *` and `int32_t > *` are simply two unrelated pointer types. unrelated, and in fact the pointed types HAVE different requisites of alignment. But I expected casting from the MORE restrictive to the LESS one, would not give problems. > For `static_cast` > that's the end of the line. > > You wanna transgress to lower level representations and > re-interpret `int32_t` object representation as a sequence > of bytes? That's what `reinterpret_cast` is for. And that's > where the matters of alignment begin to kick in. intresting, I will study this keyword, thank > -- 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
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