View Single Post
  #4   Spotlight this post!  
Unread 05-11-2004, 12:31
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Can't use pointers nor refrences.

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.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me