C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Make all data pointers intercompatible

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 9 May 2024 12:20:54 +0200
Il 09/05/24 12:00, Frederick Virchanza Gotham via Std-Proposals ha scritto:
>
> Same size, same representation, same alignment. So you can do the following:
>
> char *Func(char *arg)
> {
> double*p1 = (double*)arg;
> int*p2 = (int*)p1;
> std::string*p3 = (std::string*)p2;
> return (char*)p3;
> }
>
> The above function would be well-formed with well-defined behaviour,

Why should this code be well-formed? Strict aliasing is a thing, even in
a world of intercompatible pointers.

--
Giuseppe D'Angelo

Received on 2024-05-09 10:20:59