Re: Casting function pointers



Le Wed, 30 Jan 2008 10:46:26 -0800, KKL a écrit:

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;
(void ()(void)* ) funcPtr does not make any sense.
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.
Is your code compiles ? No offense, If so i wish you good luck (and
therefore to those who work with you)

--
HBV
.



Relevant Pages