Date: Sun, 8 Dec 2024 14:54:53 +0100
Not initialized values are the source of many non-standards conforming
code as their use is undefined. C++ is a performance first language, and
allowing non initialized variables that will be assigned a value later
before use is reasonable.
But I propose that this should be explicit, rather than implicit. A
programmer should make their intent clear that they do not want to
initialize a variable.
To do that, a new syntax should be introduced, such as assigning the
keyword void via operator= or constructor call.
```cpp
int x{void};
int y(void);
int z = void;
int a[10]{void};
```
This makes the intent clear that those variables are not initialized,
and initialization wasn't just forgotten by mistake.
Additionally the default should be a default initialized value: `int
zero;` should be zero. This will not break existing code, as any
standards compliant code wouldn't have been using the 0 value and
assigning a different value anyhow. This syntax should be marked
deprecated, and potentially removed entirely in the future, in favor of
explicit default initializing: `int zero{};`, `int zero{0}`, `int zero = 0;`
code as their use is undefined. C++ is a performance first language, and
allowing non initialized variables that will be assigned a value later
before use is reasonable.
But I propose that this should be explicit, rather than implicit. A
programmer should make their intent clear that they do not want to
initialize a variable.
To do that, a new syntax should be introduced, such as assigning the
keyword void via operator= or constructor call.
```cpp
int x{void};
int y(void);
int z = void;
int a[10]{void};
```
This makes the intent clear that those variables are not initialized,
and initialization wasn't just forgotten by mistake.
Additionally the default should be a default initialized value: `int
zero;` should be zero. This will not break existing code, as any
standards compliant code wouldn't have been using the 0 value and
assigning a different value anyhow. This syntax should be marked
deprecated, and potentially removed entirely in the future, in favor of
explicit default initializing: `int zero{};`, `int zero{0}`, `int zero = 0;`
Received on 2024-12-08 13:55:00