|
|
View previous topic :: View next topic |
Author |
Message |
Chris Burger Guest
|
pointers to functions |
Posted: Wed Jul 23, 2003 1:55 pm |
|
|
Hello,
After sending my question about arguments to IntServRoutine and the positive response from the forum members (I like to thank you for that) I have developed my program further more.
In the book ‘PICmicro MCU C’ of Nigel Gardner I have found some information about passing pointers to Functions. On page 111 he is giving two examples. I have adopted the examples to my program and the first program with the & operator is working the second(with *) NOT.
Can anyone explain that?
#include <16f84.h>
void leesSchak(int &cnt, int &pnt)
{ cnt = 9;
if (INPUT(PIN_A3) == 1) // is pin_A3 1 -> pointl = 00
pnt = 0x00;
if (INPUT(PIN_A3) == 0)
pnt = 0x09; // is pin_A3 0 -> pointl = 09
}
void main(void)
{
leesSchak(count, point);
while(1)
{ }
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// this one is NOT working correctly
void leesSchak(int *cnt, int *pnt)
{ *cnt = 9;
if (INPUT(PIN_A3) == 1) // is pin_A3 1 -> pnt = 00
*pnt = 0x00;
if (INPUT(PIN_A3) == 0)
*pnt = 0x09; // is pin_A3 0 -> pnt = 09
}
void main(void)
{
leesSchak(count, point);
while(1)
{ }
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516296 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: pointers to functions |
Posted: Wed Jul 23, 2003 2:17 pm |
|
|
:=// this one is NOT working correctly
:=void leesSchak(int *cnt, int *pnt)
:={ *cnt = 9;
:= if (INPUT(PIN_A3) == 1) // is pin_A3 1 -> pnt = 00
:= *pnt = 0x00;
:= if (INPUT(PIN_A3) == 0)
:= *pnt = 0x09; // is pin_A3 0 -> pnt = 09
:=}
:=
:=void main(void)
:={
The function as declared, is expecting pointers to arguments,
but you're passing it values. You need to give it the
addresses of the values. Change it to be:
leesSchak(&count, &point);
:= leesSchak(count, point);
:=while(1)
:= { }
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516297 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|