Casting function pointers
- From: KKL <kishore.luthra@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 10:46:26 -0800 (PST)
I wonder how casting with function pointers work, how it "should be"
handled and how it "should not be" handled. Can anyone tell whether
the below code should work or not?
Module: Task Service Abstraction Layer
int taskCreate(char* taskName, void* funcPtr, int
taskPriority,..........)
{
myTaskStructure TaskProperties;
int TaskId, errStatus;
............
//Casting void* funcPtr to function pointer that returns void and
accepts no arguments
TaskProperties.entryPtr = (void ()(void)* ) funcPtr;
errStatus = rtosTaskCreate( taskName, &TaskProperties, &TaskId);
.........
}
Module: SomeClass.cpp
void someClass::taskLoop( int taskArgument)
{
........
}
void somClass::initialize( void )
{
taskCreate( "Task1", (void* )&taskLoop, 25,.....);
}
Module: SomeOtherClass.cpp
int myTaskEntryReturnsInt( void )
{
}
SomeOtherClass::initialize( void )
{
taskCreate( "Task2", (void* )&myTaskEntryReturnsInt, 30,.....);
}
Module: AnotherClass.cpp
void myTaskEntryTakesInt( int TaskArg )
{
}
AnotherClass::initialize( void )
{
taskCreate( "Task3", (void* )&myTaskEntryTakesInt, 40,.....);
}
My question is whether these kind of casting for function pointers is
valid. If valid should it work with a predictable behavior or the
behavior is undefined.
.
- Follow-Ups:
- Re: Casting function pointers
- From: David Brown
- Re: Casting function pointers
- From: Habib Bouaziz-Viallet
- Re: Casting function pointers
- From: Hans-Bernhard Bröker
- Re: Casting function pointers
- From: andrew queisser
- Re: Casting function pointers
- From: Vladimir Vassilevsky
- Re: Casting function pointers
- From: Arlet
- Re: Casting function pointers
- Prev by Date: Ubuntu versus Fedora for cross-development host
- Next by Date: Re: Ubuntu versus Fedora for cross-development host
- Previous by thread: Ubuntu versus Fedora for cross-development host
- Next by thread: Re: Casting function pointers
- Index(es):
Relevant Pages
|