digitalmars.D.learn - Is variable void?
- John Chapman (6/6) Nov 25 2017 Is there any way of determining whether a variable has been
- rikki cattermole (5/12) Nov 25 2017 `` = void;`` isn't null.
- Adam D. Ruppe (3/6) Nov 25 2017 nope. It'd be indistinguishable from the user just happening to
- John Chapman (3/5) Nov 25 2017 Thanks. I'll got with .init instead.
- crimaniak (2/8) Nov 26 2017 You can use Nullable!int
- codephantom (19/25) Nov 26 2017 // ----------------------------------
- bauss (2/30) Nov 27 2017 null != void
- codephantom (2/3) Nov 27 2017 "initialized or not?" != void
- codephantom (8/9) Nov 27 2017 also...void is a completely useless concept for initialisation.
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?
Nov 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.
Nov 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.
Nov 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.
Nov 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: 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
Nov 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?// ---------------------------------- 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); } // ----------------------------------
Nov 26 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:null != voidIs 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); } // ----------------------------------
Nov 27 2017
On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:null != void"initialized or not?" != void
Nov 27 2017
On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:null != voidalso...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.
Nov 27 2017