简体   繁体   中英

Typecasting an address to Function pointer

I have particular code which comes from u-boot, bootloader where address being typecast to function pointer but not sure for what purpose that's is being done

 void    (*kernel)(bd_t *, ulong r4, ulong r5, ulong r6,ulong r7, ulong r8, ulong r9);//prototype


 kernel = (void (*)(bd_t *, ulong, ulong, ulong,ulong, ulong, ulong))images->ep;

Is in first statement registers r4,r5,r6,r7,r8,r9 gets initialized when later function is called??

where images->ep is address of memory and bd_ t is bord information structure.

Can anybody let me know purpose of typing casing address into function pointer.

Well, presumably they're going to call that pointer as a function at some point. The fact that the original structure entry's name is ep is telling - that probably stands for "entry point". Is there something like:

kernel(....) // appropriate arguments inserted

or

(*kernel)(....)

Found later in the code?

As you mentioned, images->ep is an "address of memory", which presumably means it's some kind of pointer type. In standard C, conversions between pointer types require an explicit cast (unless one of them is void * ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM