C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 28 Jan 2025 09:38:35 -0800
On Tuesday 28 January 2025 01:42:20 Pacific Standard Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> Therefore I think we can make the following assertion:
>
> sizeof(void*) == sizeof(char*) == sizeof( any class pointer )

Yes, we can.

> This means that we should be able to do the following:
> class SomeClass;
> void *GiveMeBackTheArgumentUnchanged(void *const arg)
> {
>
> SomeClass *const p = static_cast<SomeClass*>(arg);
> return p;
>
> }

That's part of the language, yes.

> The only complication though is that the following pointers could
>
> still be smaller than a void*:
> short*
> int*
> long*
> long long*
> float*
> double*
> long double*
>
> But since there's no compiler alive today that actually does that, I
> think C++26 should mandate that all data pointers are the same size
> and representation.

Why? What do we gain by doing that? What can we do once we have this
information that we couldn't before?

I don't think we *lose* anything by doing it. I just don't see the benefit.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-01-28 17:38:39