|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Can't use pointers nor refrences.
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"
|
|
#2
|
|||||
|
|||||
|
Re: Can't use pointers nor refrences.
Pointers worked fine for me, once I got the hang of the syntax. I don't often use C, and I find it very nonintuitive.
|
|
#3
|
|||||
|
|||||
|
Re: Can't use pointers nor refrences.
Quote:
|
|
#4
|
|||||
|
|||||
|
Re: Can't use pointers nor refrences.
Quote:
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;
}
}
"*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); 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. |
|
#5
|
||||
|
||||
|
Re: Can't use pointers nor refrences.
Sort of offtopic, but do you know why IFI used a pointer in the Limit_Switch_Max() function? I can't see any good reason except possibly to show that it could be done?
|
|
#6
|
|||
|
|||
|
Re: Can't use pointers nor refrences.
Quote:
|
|
#7
|
||||||
|
||||||
|
Re: Can't use pointers nor refrences.
Quote:
Or is that what you referring to? |
|
#8
|
||||
|
||||
|
Re: Can't use pointers nor refrences.
Sorry, I should have been a bit more clear. I know they were passing it by pointer so they could change it inside the function, but I would have thought it better practice to return the value than output from inside the function. Isn't it good practice, in general, to have functions be as close to real mathematical functions as possible (one set of inputs always maps to the same outputs and the only outputs are what the function returns)
Last edited by Max Lobovsky : 05-11-2004 at 14:41. |
|
#9
|
||||
|
||||
|
Re: Can't use pointers nor refrences.
Quote:
Steve Last edited by Steve Shade : 05-11-2004 at 15:45. Reason: spelling |
|
#10
|
||||
|
||||
|
Re: Can't use pointers nor refrences.
Quote:
) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointers to structs? | Jeff McCune | Programming | 2 | 17-02-2004 13:17 |
| Laser Pointers.. | archiver | 2001 | 18 | 24-06-2002 00:08 |