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 CCS Technical Support

function pointers

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







function pointers
PostPosted: Fri Nov 19, 2004 3:11 am     Reply with quote

Hi,

I have a problem in using function pointers.The code is given below.

void taskcreate( void (*tsk) (void *stk),void *ptr,unsigned char x,unsigned char y);

task1(void *p)
{
---
---
}

main()
{
void *s;
unsigned char a,b;
---;
---;
createtask(tsak1,s,a,b);
---;
---;
}


void taskcreate( void (*tsk) (void *stk),void *ptr,unsigned char x,unsigned char y) // compiler error
{
-----;
-------;
}

compiler error is :"Function definition different from previous definition".

Then I changed both declaration and defintion of function "taskcreate" as

unsigned char taskcreate( void *tsk,void *ptr,unsigned char x,unsigned char y);


task1(void *p)
{
---;
---;
}

void (*t) (void *ptr);

main()
{
void *s;
unsigned char a,b;

t=task1; //*********
---;
---;
createtask(t,s,a,b);
---;
---;
}


unsigned char taskcreate( void *task,void *ptr,unsigned char x,unsigned char y)
{
void (*fnptr)( void *ptr);
fnptr=task;
(*fnptr) ( ptr);
-----;

-------;
}

Thsi method works well. But I need to call the function "taskcreate()" from main() by specifying the name of the function as given below.

main()
{
void *s;
unsigned char a,b;
---;
---;
createtask(task1,s,a,b); // Needed help
---;
---;
}


What are funtion pointer methods avialable in CCS compiler?.Otherwise please suggest me a method to solve this problem.


GS Prabhu,


Code:
Ttelmah
Guest







PostPosted: Fri Nov 19, 2004 4:10 am     Reply with quote

I suspect your problem is a common one with the CCS C, with regards to how 'voids' behave. In the original K&R defintions, a 'void', was a pseudonym for 'nothing', and a function returning 'void', could not return anything at all. Similarly, a function requiring a 'void', would not expect to receive any data at all. This is how 'voids' bechave in CCS.
Ansi C, then introduced the idea of a 'untyped' void. With this, a function could be defined to return a 'void', and could still return a value. When this was done, the returned data type, became a 'generic' type, which was automatically cast to fit the target. Void then becomes useable as a sort of 'undefined' type. This is not supported in CCS C.
Hence if you are using a pointer to a function, which may return something, it should be declared to return a type (for a pointer, and int16, rather than a unsigned char), and then 'cast' on use to the required type.

Best Wishes
Trampas



Joined: 04 Sep 2004
Posts: 89
Location: NC

View user's profile Send private message MSN Messenger

PostPosted: Sat Nov 20, 2004 7:56 am     Reply with quote

I suspect that the CCS compiler is broken and you can not use pointers to functions. I know I have tried and it does not work.

Trampas
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sat Nov 20, 2004 10:53 am     Reply with quote

In the "common questions and answers" section of the reference manual,
"The compiler does not permit pointers to functions so that the complier can know at compile time the complete call tree. This is used to allocate memory for full RAM re-use".
_________________
David
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Nov 20, 2004 11:55 am     Reply with quote

Quote:
In the "common questions and answers" section of the reference manual,
"The compiler does not permit pointers to functions so that the complier can know at compile time the complete call tree. This is used to allocate memory for full RAM re-use".


The manual is outdated!

See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=20416
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sun Nov 21, 2004 11:42 am     Reply with quote

I guess that means that the trusty old "read the manual" can't be trusted anymore. Thanks CCS!
_________________
David
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