Re: Casting function pointers
- From: Habib Bouaziz-Viallet <habib@xxxxxxxxxxxxx>
- Date: 31 Jan 2008 19:44:19 GMT
Le Thu, 31 Jan 2008 10:35:11 -0800, KKL a écrit:
On Jan 31, 12:18 pm, Habib Bouaziz-Viallet <ha...@xxxxxxxxxxxxx>Hi KKL !
wrote:
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
Hi Habib,
Is there a real difference between a clear mind and a clear syntax?
I am a new use to the group and did not know that putting code
snippets that do not compile is such a serious offense even if you are
discussing here some logical issues here and not syntactical ones.
The clear syntax reveals a clear thought.
It is believed that the often obscure code is effective but most of
the time it is not.
I agrre with you, the logical errors are those that cost the most and
Ok, so I accept my offense that the code snippets have syntactical
issues and that is because I did not simply copy it from my C source
files but just wrote it in hurry to put up an example for my point of
discussion which was "IS TYPE CASTING FUNCTION POINTERS FROM void (*)
(int) TO (void *) AND BACK TO void (*)(void) AND THEN USING IT TO
CALL FUNCTIONS IS A VALID AND SAFE OPERATION OR NOT".
And regarding your comment about Good luck to those that work with me,
may be you don't know that if making logical mistakes costs you much
more than making syntactical mistakes and those mistakes are mostly
done by people who stresses more on syntax rather than the actual
thing which is LOGIC. So a good luck is required more to people who
miss the whole point and and try hard to prove their knowledge
stressing on the syntax (since that itself is hard thing for them).
therefore there is no need to add syntax errors.
Yes.
So, now I think you know what it means to take offense.
Regards
Best regards KKL,
--
HBV
.
- References:
- Casting function pointers
- From: KKL
- Re: Casting function pointers
- From: Habib Bouaziz-Viallet
- Re: Casting function pointers
- From: KKL
- Casting function pointers
- Prev by Date: Re: Casting function pointers
- Next by Date: Re: STR912 RTC Crystal
- Previous by thread: Re: Casting function pointers
- Next by thread: Re: Casting function pointers
- Index(es):
Relevant Pages
|