Re: Casting function pointers



Le Thu, 31 Jan 2008 10:35:11 -0800, KKL a écrit:

On Jan 31, 12:18 pm, Habib Bouaziz-Viallet <ha...@xxxxxxxxxxxxx>
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,
Hi KKL !

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.
Is there a real difference between a clear mind and a clear syntax?
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.


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).
I agrre with you, the logical errors are those that cost the most and
therefore there is no need to add syntax errors.

So, now I think you know what it means to take offense.
Yes.

Regards

Best regards KKL,



--
HBV
.



Relevant Pages

  • failed build for tk-8.4.5,1 and bittorrent
    ... error: syntax error before "ClientData" ... error: syntax error before "VOID" ... syntax er ror before "int" ... error: ...
    (freebsd-questions)
  • Re: Casting function pointers
    ... int taskCreate(char* taskName, void* funcPtr, int ... No offense, If so i wish you good luck (and ...
    (comp.arch.embedded)
  • Re: Casting function pointers
    ... Module: Task Service Abstraction Layer ... int taskCreate(char* taskName, void* funcPtr, int ...
    (comp.arch.embedded)
  • Re: would C be easier to read if...
    ... "pointer to function taking a void * argument and returning void ... tend to written linearly, from left to right, the same as my syntax. ... "Pointer to Function taking Pointer to Int parameter and returning Pointer ...
    (comp.lang.c)
  • Re: Defining an alias
    ... int Enqueue(List *l, void *item) ... (which of course is a new syntax, but does away with the extra obfuscating indirection layer.) ... alias Enqueue = Add; ...
    (comp.lang.c)