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@lists.isocpp.org> w dniu 16 lut 2025, o godz. 17:03:

 AW: [std-proposals] Delayed const declaration

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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals