Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - What does this line mean?

I am trying to understand what the following line of the worst-ever-seen C code (from uboot project) mean:

rc = ((ulong (*)(bd_t *, int, char *[]))addr) (bd, --argc, &argv[1]);

What is it? A function call? Can it be more readable?

Thanks in advance for your help!

like image 248
psihodelia Avatar asked Jan 13 '10 15:01

psihodelia


People also ask

What does C underline mean?

The symbol "⊆" means "is a subset of". The symbol "⊂" means "is a proper subset of". Example. Since all of the members of set A are members of set D, A is a subset of D. Symbolically this is represented as A ⊆ D.

What does C with a bar under it mean?

The C with bar (majuscule: Ꞓ, minuscule: ꞓ), also known as barred C, is a modified letter of the Latin alphabet, formed from C with the addition of a bar.

What does C mean on a prescription?

capsule. c. cum. with (usually written with a bar.


1 Answers

Yes, it's a function call.

It casts the value in addr to a function pointer which accepts (bd_t *, int, char *[]) as arguments and returns a ulong, and calls the function. It could be sugared into:

typedef ulong (*bd_function)(bd_t *bd, int argc, char *argv[]);

bd_function bdfunc = (bd_function) addr;

rc = bdfunc(bd, --argc, &argv[1]);

This might be overkill, to introduce a typedef if this only happens once, but I feel it helps a lot to be able to look at the function pointer's type separately.

like image 92
unwind Avatar answered Oct 04 '22 17:10

unwind