www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Are void arrays usable ?

reply "badlink" <andrea.9940 gmail.com> writes:
Hello,
I just discovered this strange behavior:

struct A {
   void[10] x; // OK, compiles fine
}
class B {
   void[10] x; // Error: void does not have a default initializer
               // ! note, the message come without any line 
indication !
}

Does this mean that void arrays are a thing or it is a bug ?
Sep 20 2014
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
badlink:

 Does this mean that void arrays are a thing or it is a bug ?
You can compile that with: class Foo { void[10] x = void; } But this code shows a dmd bug (lack of line number): class Foo { void[10] x; } void main() {} Error: void does not have a default initializer Take a look in bugzilla, if it's not already present file it. Bye, bearophile
Sep 20 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
 Take a look in bugzilla, if it's not already present file it.
https://issues.dlang.org/show_bug.cgi?id=13505 Bye, bearophile
Sep 20 2014
prev sibling parent "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
On Sat, Sep 20, 2014 at 10:09:25AM +0000, badlink via Digitalmars-d-learn wrote:
 Hello,
 I just discovered this strange behavior:
 
 struct A {
   void[10] x; // OK, compiles fine
 }
 class B {
   void[10] x; // Error: void does not have a default initializer
               // ! note, the message come without any line indication !
 }
 
 Does this mean that void arrays are a thing or it is a bug ?
void[] is a wildcard array type that represents a block of memory that contains an array of some sort. It behaves like ubyte[], except that it may be GC-scanned for pointers (ubyte[] AFAIK is not scanned because you're not expected to store pointers in it, but void[] represents *any* array and thus may contain pointers). T -- Not all rumours are as misleading as this one.
Sep 20 2014