[ODE] dBodyGet*

Nate W coding at natew.com
Wed Mar 19 23:02:01 2003


On Thu, 20 Mar 2003, [ISO-8859-1] amundbørsand wrote:

> [.....] If I try to set up something like this:
> 
> dReal *R=dBodyGetRotation(myBody);
> 
> the compiler complains that "assignment to `dReal *' from `const dReal *'
> discards qualifiers". I'm not sure I understand what "const" really
> means in this context [.....]

"const" is a ways of saying "this is read-only information," and having
the compiler enforce that rule.  If you try to change the value of an
object that's been declared const, the compiler will complain.  So, by
having dBodyGetRotation return a "const dReal *" Russ is basically saying
that you can read the rotation matrix, but you're not allowed to change it.

The compiler requires that you store the results in a "const dReal *" so
that it stays const.  If you assigned it to a non-const "dReal *" then the
compiler wouldn't know you weren't supposed to change it, so it would let
you change it, that would be bad.  (You can actually assign to a non-const
object, using a cast, but you shouldn't.)

> [...] but if I change to
> 
> const dReal *R=dBodyGetRotation(myBody);
> 
> everything compiles fine, but crashes immediately. 

Immediately when?

When you call dBodyGetRotation, or when you try to access the data in R?

In any case, I'd suspect that myBody doesn't refer to an actual Body.  
Any chance you're passing in a bogus value there?

-- 

Nate Waddoups
Redmond WA USA
http://www.natew.com