C++ Logo

std-proposals

Advanced search

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

From: Bo Persson <bo_at_[hidden]>
Date: Tue, 28 Jan 2025 10:51:33 +0100
On 2025-01-28 at 10:42, Frederick Virchanza Gotham via Std-Proposals wrote:
> Not entirely sure where this thread has ventured off to, but let me
> get back to what I was talking about (i.e. the size of pointers).
> Given the following translation unit:
>
> class MyClass;
> MyClass *my_global_variable;
>
> The compiler doesn't know the alignment requirements of MyClass. For
> instance it might be:
>
> struct MyClass { char c; };
>
> or it could be:
>
> struct MyClass { long double f; };
>
> Therefore I think we can make the following assertion:
>
> sizeof(void*) == sizeof(char*) == sizeof( any class pointer )
>

No, the relation is >=, not ==.

A void* must be able to hold the other pointer types, so it cannot be
smaller. Not smaller is not the same as not larger.

Received on 2025-01-28 09:51:37