Quote:
|
Originally Posted by cibressus53
Has anyone had any sucess with using pointers or refrences? I thought MLAB was C '89 compleient, I thought pointers atleast were in the orignal C "release"
|
Pointers work just fine. Here's a simple example from the default code (in user_routines.c):
Code:
/*******************************************************************************
* FUNCTION NAME: Limit_Switch_Max
* PURPOSE: Sets a PWM value to neutral (127) if it exceeds 127 and the
* limit switch is on.
* CALLED FROM: this file
* ARGUMENTS:
* Argument Type IO Description
* -------- ------------- -- -----------
* switch_state unsigned char I limit switch state
* *input_value pointer O points to PWM byte value to be limited
* RETURNS: void
*******************************************************************************/
void Limit_Switch_Max(unsigned char switch_state, unsigned char *input_value)
{
if (switch_state == CLOSED)
{
if(*input_value > 127)
*input_value = 127;
}
}
"unsigned char *input_value" says that "input value" is a pointer to an "unsigned char" type variable.
"*input_value > 127" and "*input_value = 127" are references to the value stored where the pointer... uh... points.
Later on in the same source file, you can find examples of how this function is called:
Code:
Limit_Switch_Max(!rc_dig_in05, &pwm03);
This line passes the address of the pwm03 variable to the Limit_Switch_Max function for it to use as a pointer back to the memory location occupied by the pwm03 variable.
Does this help? If you can give us some clues about what you're trying to do with pointers (and how much you already know or don't know about pointers), I imagine we can be a little more helpful.