btDbvt.h array initialization issue

Tassilo
Posts: 2
Joined: Tue Feb 24, 2009 2:43 pm

btDbvt.h array initialization issue

Post by Tassilo »

Hi,

I just stumbled upon the following line in btDbvt.h (2.73) which seem wrong to me:

Code: Select all

	btScalar			s1[2]={dot(xform.getOrigin(),d0),s1[0]};
s1 is used before a value is set...
Just wanted to report this.

Cheers
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btDbvt.h array initialization issue

Post by Erwin Coumans »

Apparently the order of evaluation requires s1[1] to be initialized before s1[0], so the current implementation is correct.

The btDbvt::Intersect function has been taken out in Bullet 2.74, because it was unused. If it still existed, the implementation would have been more clear like this:

Code: Select all

btScalar tmp=dot(xform.getOrigin(),d0);
btScalar         s1[2]={tmp, tmp};
Thanks,
Erwin
Tassilo
Posts: 2
Joined: Tue Feb 24, 2009 2:43 pm

Re: btDbvt.h array initialization issue

Post by Tassilo »

Hi,

since it is possible to just use uninitialized variables in C/C++ (if it makes sense is another question), IMHO s[1] doesn't "require" s[0] to be initialized. The language standard does not specify the order of evaluation of expressions other than for ||, &&, comma and the ?: operators (which are explicitly specified in C++ 5.14, 5.15 and C99 6.5.13 and 6.5.14).
But well, it might be that I overlooked something, of course.

Well, in any case, your second snippet is guaranteed to be correct.

Cheers