digitalmars.D - null assignment to bit variable
- Peter Thomassen (11/11) Aug 14 2006 Hi,
- Sean Kelly (5/17) Aug 14 2006 bool* test = null;
- Peter Thomassen (6/10) Aug 15 2006 This looks nice ... but how do I read / write the value of test? After
- Sean Kelly (8/16) Aug 15 2006 The other suggestion to use an enum is a better one. To use the bool
- Peter Thomassen (3/7) Aug 15 2006 And how would I set it false?
- Chris Nicholson-Sauls (3/14) Aug 15 2006 *test = false;
- Peter Thomassen (3/6) Aug 16 2006 I'm that stupid -- thanks.
- Chris Miller (13/24) Aug 14 2006 =
- Unknown W. Brackets (19/34) Aug 14 2006 Just remember, D is not PHP :).
Hi, the following doesn't work: bit test; test = null; I understand that this is not possible, but coming from the PHP world, I'm looking for a way to define that "test" hasn't got a value yet, not even true or false. Is that possible? Is there a workaround? Thanks! Peter
Aug 14 2006
Peter Thomassen wrote:Hi, the following doesn't work: bit test; test = null; I understand that this is not possible, but coming from the PHP world, I'm looking for a way to define that "test" hasn't got a value yet, not even true or false. Is that possible? Is there a workaround?bool* test = null; test = new bool; (note that bit has been replaced by bool in recent versions of D) Sean
Aug 14 2006
Sean Kelly schrieb am Dienstag, 15. August 2006 03:34:bool* test = null; test = new bool;This looks nice ... but how do I read / write the value of test? After assigning "new bool", reading it gives a memory address, and writing fails. Maybe I should've posted to digitalmars.D.learn :-)(note that bit has been replaced by bool in recent versions of D)Thanks. Peter
Aug 15 2006
Peter Thomassen wrote:Sean Kelly schrieb am Dienstag, 15. August 2006 03:34:The other suggestion to use an enum is a better one. To use the bool above you have to dereference the pointer: if( test !is null && *test ) { // something that requires test to be set and true } Seanbool* test = null; test = new bool;This looks nice ... but how do I read / write the value of test? After assigning "new bool", reading it gives a memory address, and writing fails. Maybe I should've posted to digitalmars.D.learn :-)
Aug 15 2006
Sean Kelly schrieb am Dienstag, 15. August 2006 23:59:if( test !is null && *test ) { // something that requires test to be set and true }And how would I set it false? Peter
Aug 15 2006
Peter Thomassen wrote:Sean Kelly schrieb am Dienstag, 15. August 2006 23:59:*test = false; -- Chris Nicholson-Saulsif( test !is null && *test ) { // something that requires test to be set and true }And how would I set it false? Peter
Aug 15 2006
Chris Nicholson-Sauls schrieb am Mittwoch, 16. August 2006 02:01:I'm that stupid -- thanks. PeterAnd how would I set it false?*test = false;
Aug 16 2006
On Mon, 14 Aug 2006 21:22:54 -0400, Peter Thomassen = <info peter-thomassen.de> wrote:Hi, the following doesn't work: bit test; test =3D null; I understand that this is not possible, but coming from the PHP world,==I'm looking for a way to define that "test" hasn't got a value yet, not ev=entrue or false. Is that possible? Is there a workaround? Thanks! PeterPerhaps bool/bit isn't even what you want. enum Foo: byte { None, True, False, } Foo f =3D Foo.None; and this requires no heap allocation or extra storage.
Aug 14 2006
Just remember, D is not PHP :). As it would happen, the way PHP/Zend does it is using a struct: enum zval_type { IS_NULL, IS_STRING, IS_INTEGER, } struct zval { zval_type type = zval_type.IS_NULL; union { char[] str_val = null; int int_val = 0; } } I'm also primarily a PHP programmer, by the way ;). -[Unknown]Hi, the following doesn't work: bit test; test = null; I understand that this is not possible, but coming from the PHP world, I'm looking for a way to define that "test" hasn't got a value yet, not even true or false. Is that possible? Is there a workaround? Thanks! Peter
Aug 14 2006