CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

pointers to functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Chris Burger
Guest







pointers to functions
PostPosted: Wed Jul 23, 2003 1:55 pm     Reply with quote

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

View user's profile Send private message

Re: pointers to functions
PostPosted: Wed Jul 23, 2003 2:17 pm     Reply with quote

:=// 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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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