"Uninitialized array" warnings by c++ with -O2
K
kyb@online.ru
Wed Jun 7 14:16:00 GMT 2017
On 06/07/2017 04:56 PM, Andrew Haley wrote:
> On 07/06/17 14:45, K wrote:
>> And I found that that a version which I beleve mustn't have aliasing
>> problems still generates same warnings.
> It still has aliasing problems: you can't make them magically go away
> by using an intermediate uint8_t*.
>
> You're doing this:
>
> struct udp_pseudo {
> uint32_t src;
> uint32_t dst;
> uint8_t z;
> uint8_t proto;
> uint16_t len;
> } tmp;
> ...
>
> auto ret = calc_16bit_checksum_part((uint8_t*)&tmp, sizeof(tmp), 0);
>
> static uint32_t calc_16bit_checksum_part(uint8_t* buf, int len, uint32_t ret) {
> struct ui16{
> uint16_t d;
> };
> ui16 *ptr = (ui16*)buf;
>
> There's no need for any of this messing about with pointer casts, as has
> been explained.
>
Sorry, but I still can't get the idea. Cast from udp_pseudo to uint8_t
doesn't have an aliasing problem (std 8.8) and a cast from uint8_t to
ui16 still doesn't have an aliasing problem (std 8.6), or may be I
missed something?
Kirill.
More information about the Gcc
mailing list