Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded C function macro problem

Tags:

c

macros

embedded

I came across this in embedded hardware using C.

#define EnterPWDN(clkcon) (  (void (*)(int))0xc0080e0 ) (clkcon) 

I have no idea how is this function macro working. I understand clkcon is the function parameter to EnterPWDN, but what is happening after that?

like image 811
zengr Avatar asked Oct 12 '10 07:10

zengr


1 Answers

It casts the address 0xc0080e0 to a pointer to function taking an int and returning void, and calls that function, passing clkcon as the parameter.

Spelled out:

typedef void (func_ptr*)(int);
func_ptr func = (func_ptr)0xc0080e0;
func(clkcon);

(If you haven't come across function pointers, you might want to grab a good C introduction and read up on the subject.)

like image 75
sbi Avatar answered Sep 30 '22 18:09

sbi