www.digitalmars.com         C & C++   DMDScript  

D - Compiler bug? Assigning to an array...

reply ssuukk <ssuukk .go2.pl> writes:
Don't know if it's compiler bug, or my bug, but according to manual this 
should work:

s[] = 3; // set all array elements to 3

But this crashes the compiler:

void identity(){
	(*this)[]=0;
	// rest of code - not important
}

Any idea how to do it properly (except for loop)?
Dec 18 2003
next sibling parent reply ssuukk <ssuukk .go2.pl> writes:
Don't know if it's compiler bug, or my bug, but according to manual this
should work:

s[] = 3; // set all array elements to 3

But this crashes the compiler:

void identity(){
     (*this)[]=0;
     // rest of code - not important
}

Any idea how to do it properly (except for loop)?


and the struct is defined as:

struct frMatrix4
{
	union
	{
		struct { frReal f11, f12, f13, f14, f21, f22, f23, f24,      			f31, 
f32, f33, f34, f41, f42, f43, f44; };
		frReal[16] f1;
		frReal[4][4] f2;
	};
...

I realise that this union may be the problem...
Dec 18 2003
parent reply "Robert" <no spam.ne.jp> writes:
This may work.

struct frMatrix4 {
    void identity() {
        f1[] = 0;
    }
}

But, union with struct has a bug.
I posted the problem some time ago.
http://www.digitalmars.com/drn-bin/wwwnews?D/19978

"ssuukk" <ssuukk .go2.pl> wrote in message
news:brs0eq$2n4b$2 digitaldaemon.com...
 Don't know if it's compiler bug, or my bug, but according to manual this
 should work:

 s[] = 3; // set all array elements to 3

 But this crashes the compiler:

 void identity(){
      (*this)[]=0;
      // rest of code - not important
 }

 Any idea how to do it properly (except for loop)?


 and the struct is defined as:

 struct frMatrix4
 {
 union
 {
 struct { frReal f11, f12, f13, f14, f21, f22, f23, f24,      f31,
 f32, f33, f34, f41, f42, f43, f44; };
 frReal[16] f1;
 frReal[4][4] f2;
 };
 ...

 I realise that this union may be the problem...
Dec 18 2003
parent ssuukk <ssuukk .go2.pl> writes:
Robert wrote:
 This may work.
 
 struct frMatrix4 {
     void identity() {
         f1[] = 0;
     }
 }
 
Thx. It may work. I will check that as soon as someone helps me with struct-static-pseudo-constructor problem :-)
Dec 18 2003
prev sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
I don't think it has anything to do with the union.  Array operations are a
currently unimplemented feature.  You can't do a[] = b[] + c[] * d either.

(Walter, don't you think it's about time to go ahead and get this feature
working?  I assume you intend to before v1.0... it is likely to have some
impact on the language as we find situations that cause problems, so it's
good to get it out of the way sooner rather than later.  Plus it's tres
useful, and will provide good parallelization opportunities.)

Sean

"ssuukk" <ssuukk .go2.pl> wrote in message
news:brs09m$2n4b$1 digitaldaemon.com...
 Don't know if it's compiler bug, or my bug, but according to manual this
 should work:

 s[] = 3; // set all array elements to 3

 But this crashes the compiler:

 void identity(){
 (*this)[]=0;
 // rest of code - not important
 }

 Any idea how to do it properly (except for loop)?
Dec 18 2003