Posts Tagged ‘Ruby’

The Evil of Macros

Wednesday, March 10th, 2010

I was doing some work on an XInput extension for Ruby, and after making some changes I stopped getting controller input data. I had a look, and somehow I’d done this :

XINPUT_STATE state;
if( SUCCEEDED( controllerIndex, &state ) )
{
...
}

Instead of:

XINPUT_STATE state;
if( SUCCEEDED( XInputGetState( controllerIndex, &state ) ) )
{
...
}

Of course, SUCCEEDED was perfectly happy with this, since the following is perfectly valid code. Unusual, but valid.

XINPUT_STATE state;
if( ((HRESULT)(controllerIndex, &state)) >= 0 )
{
...
}

Evil.