A pointer to a function is pretty standard C, it will work in both PROS and ConVEX (and EasyC if you know what to do).
I already use them in the ConVEX library, for example in the vexMotorPositionGet function I use a function pointer like this.
Notice I check for a NULL pointer before using it (as well as bounds checking the index parameter), this is important, a call to a NULL pointer will crash the code, leave the motors running and upset event organizers.
int32_t
vexMotorPositionGet( int16_t index )
{
int32_t position;
if( (index < kVexMotor_1) || (index >= kVexMotorNum))
return(0);
if( vexMotors index ].motorPositionGet != NULL )
{
position = vexMotors index ].motorPositionGet( vexMotors index ].port );
// 269 needs reversing
if( vexMotors index ].type == kVexMotor269 )
position = -position;
if(!vexMotors index ].reversed )
return( position );
else
return( -position );
}
else
return(0);
}
motorPositionGet is a pointer to a function declared like this.
int32_t (*motorPositionGet)( int16_t port );
which I set during initialization using a call to this code.
void
vexMotorPositionGetCallback( int16_t index, int32_t (*cb)(int16_t), int16_t port )
{
if( (index < kVexMotor_1) || (index >= kVexMotorNum))
return;
vexMotors index ].motorPositionGet = cb;
vexMotors index ].port = port;
}
here is the call to the above function if the encoder is a quad encoder
// set the get position callback
vexMotorPositionGetCallback( _cfg->port, vexEncoderGet, _cfg->channel );
or an IME
// set the get position callback
vexMotorPositionGetCallback( _cfg->port, vexImeGetCount, _cfg->channel );
So either vexEncoderGet or vexImeGetCount will be called when I want motor position depending on how the motor has been configured.