C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Delayed const declaration

From: Filip <fph2137_at_[hidden]>
Date: Sun, 16 Feb 2025 17:26:23 +0100
Some time ago I noticed that I usually only need to change variable only couple of times, maybe 3 :)
So I considered that we’re only interested in restricting programmers ability to write more than n times.

Just to throw it out there as a possible syntax:
const[n] int x = 0;

Writing enabled up to n times, its type could simply be const[n] int with possible equality to const int.

Cheers, Filip

> Wiadomość napisana przez Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> w dniu 16 lut 2025, o godz. 17:03:
>
> 
> For
>
>
>
> int i = 0;
>
> const i;
>
> std::cout << &i << std::endl;
>
>
>
>
>
> Would the compiler be allowed to optimize out the non-const phase of i and put it into read-only-memory?
>
>
>
>
>
> For
>
>
>
> int i = 0;
>
> std::cout << &i << std::endl;
>
> const i;
>
> std::cout << &i << std::endl;
>
>
>
>
> Would the compiler be allowed to relocate i between non-const memory and read-only-memory and print out two different addresses?
>
>
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-02-16 16:26:38