0

I wrote a function to test functions. I want to be flexible, that's the reason for the function pointer.

My code is working, but is there a possibility to avoid the warning below? I thought about a cast.

So I tried to set a (UINT32 *) in front of the &tickGet, but it isn't working.

Can you help me?

ULONG tickGet (void);

void WCET_Measurement(UINT32 (*Function)(void)){}

WCET_Measurement(&tickGet);

Compiler Warning

warning: passing arg 1 of `WCET_Measurement' from incompatible pointer type
1
  • 1
    why use both ULONG and UINT32? have you tried using one of those? Commented Jan 16, 2013 at 14:21

2 Answers 2

3

Casting function pointers is well-defined. However, invoking a function through an incompatible pointer is undefined behaviour. So if UINT32 is a distinct type from a ULONG, then things will be wrong.

But if you really want to cast, then you can do this:

WCET_Measurement((UINT32 (*)(void))&tickGet);

Or better yet, use a typedef:

typedef UINT32 (*MyFunc)(void);

WCET_Measurement((MyFunc)&tickGet);
Sign up to request clarification or add additional context in comments.

2 Comments

@user1829804: Are you sure you copied my example precisely?
SORRY, don'T know what but It was my fault
1

Your cast attempt was wrong.

You need:

WCET_Measurement(((UINT32)(*)(void)) tickGet);

It's often good to use a typedef with function pointers, to make them clearer.

Of course, if the two types UINT32 and ULONG are different on your system, this will break horribly.

1 Comment

SORRY, don'T know what but It was my fault

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.