C++ Logo

std-proposals

Advanced search

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

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Tue, 28 Jan 2025 15:36:09 +0000
Which in my view it's the right thing to do.

ptr size is a red herring, ptr requirements is what kills it.

Concerns over ptr size are irrelevant, platforms would either already be compliant or would never be compliant because of implantation details. The only thing that changing the text would achieve is to make certain systems de-facto non-compliant for no reason.

The OP is not interested in behavior related to platforms were pointers are of different sizes (he's explicitly asking for the support for those systems to be dropped), but behavior were pointers are already the same size.

But what is being asked is to explicitly ignore ptr requirements, which is intentionally left undefined, and should not be changed on any platform.

So no, pointers should not be "intercompatible" in this sense.


________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]>
Sent: Tuesday, January 28, 2025 3:40:32 PM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Sebastian Wittmeier <wittmeier_at_[hidden]>
Subject: Re: [std-proposals] Make all data pointers intercompatible


According to CPP Reference this is currently not okay:

"If expression represents the address<https://en.cppreference.com/w/cpp/language/pointer#Pointers> A of a byte<https://en.cppreference.com/w/cpp/language/memory_model#Byte> in memory but A does not satisfy the alignment<https://en.cppreference.com/w/cpp/language/object#Alignment> requirement of T, then the resulting pointer value is unspecified."

https://en.cppreference.com/w/cpp/language/static_cast


-----Ursprüngliche Nachricht-----
Von: organicoman via Std-Proposals <std-proposals_at_[hidden]>
No it could not, and it is not allowed. The only thing you will MAYBE get is a misaligned pointer to a double memory location, and you should not dereference that pointer, because of aliasing incompatibility otherwise UB.

Try the following code:
#include <stdio.h>

int main()
{
    char arr[8];
    double* ptr = static_cast<double*>(static_cast<void*>(arr+3));


Received on 2025-01-28 15:36:13