Thread overview
Is variable void?
Nov 25, 2017
John Chapman
Nov 25, 2017
rikki cattermole
Nov 25, 2017
Adam D. Ruppe
Nov 25, 2017
John Chapman
Nov 26, 2017
crimaniak
Nov 27, 2017
codephantom
Nov 28, 2017
bauss
Nov 28, 2017
codephantom
Nov 28, 2017
codephantom
November 25, 2017
Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:

  int x = void;

can I check if it's void before I use it, say, in a function it's been passed to?

November 25, 2017
On 25/11/2017 3:34 PM, John Chapman wrote:
> Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:
> 
>    int x = void;
> 
> can I check if it's void before I use it, say, in a function it's been passed to?

`` = void;`` isn't null.

Don't treat it as such. It is a low level detail where you _will_ initialize it, just in a smarter way.

There is no conditions tied directly to it.
November 25, 2017
On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
> Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:

nope. It'd be indistinguishable from the user just happening to initialize it to some random value.

November 25, 2017
On Saturday, 25 November 2017 at 15:38:15 UTC, Adam D. Ruppe wrote:
> nope. It'd be indistinguishable from the user just happening to initialize it to some random value.

Thanks. I'll got with .init instead.

November 26, 2017
On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
> Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:
>
>   int x = void;
>
> can I check if it's void before I use it, say, in a function it's been passed to?

 You can use Nullable!int
November 27, 2017
On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
> Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:
>
>   int x = void;
>
> can I check if it's void before I use it, say, in a function it's been passed to?

// ----------------------------------

module test;

import std.stdio;
import std.typecons; // see: https://dlang.org/phobos/std_typecons.html#Nullable

void main()
{
    Nullable!int x;  // requires: import std.typecons
    assert(x.isNull);
    writeln("x is ", x);

    x = 1;
    assert(!x.isNull);
    writeln("x is ", x);

    x.nullify(); //  	Forces x back to a null state.
    assert(x.isNull);
    writeln("x is ", x);

}
// ----------------------------------

November 28, 2017
On Monday, 27 November 2017 at 02:12:40 UTC, codephantom wrote:
> On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
>> Is there any way of determining whether a variable has been initialized or not? For example, if something is declared like this:
>>
>>   int x = void;
>>
>> can I check if it's void before I use it, say, in a function it's been passed to?
>
> // ----------------------------------
>
> module test;
>
> import std.stdio;
> import std.typecons; // see: https://dlang.org/phobos/std_typecons.html#Nullable
>
> void main()
> {
>     Nullable!int x;  // requires: import std.typecons
>     assert(x.isNull);
>     writeln("x is ", x);
>
>     x = 1;
>     assert(!x.isNull);
>     writeln("x is ", x);
>
>     x.nullify(); //  	Forces x back to a null state.
>     assert(x.isNull);
>     writeln("x is ", x);
>
> }
> // ----------------------------------

null != void
November 28, 2017
On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:
> null != void

"initialized or not?" != void


November 28, 2017
On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:
> null != void


also...void is a completely useless concept for initialisation.

what can you determine about the nothingness of void? ... nothing.


writeln(typeof(void).stringof); // ?? what do I know now? nothing.

vs

Nullable!int x;
writeln(typeof(x).stringof); // Nullable!int .. now I know something.