Initialize to None

Steven Schveighoffer schveiguy at gmail.com
Sun Sep 6 03:56:51 UTC 2020


On 9/5/20 11:42 PM, N.S. wrote:
> I'd like to check whether a variable is initialized or not. And I'd also 
> like to uninitialize a variable that is already initialized. Thanks!
> 
> int x = void;
> 
> if (x == void)

There isn't a way to check this.

> {
>      writeln("x not initialized");
> }
> else
> {
>      // OK, use x
> }
> 
> // Uninitialize x
> x = void;
> 

When you set the initial value of x to void, it means "don't do 
anything, let whatever data is already on the stack be the value of x".

So "uninitialize" doesn't really mean anything. It would technically 
mean "do nothing".

-Steve


More information about the Digitalmars-d-learn mailing list