0

I ran across a line of code that looks like the following:

typedef Foo* (*CREATE_BAR)(uint32_t);

How exactly does this work? What is happening in this code?

randombits
  • 47,058
  • 76
  • 251
  • 433
  • 1
    It's at times like these when http://cdecl.ridiculousfish.com/ is helpful... Of course you'd have to already know that `Foo` was a type and swap it for a primitive type, like: [`int* (*CREATE_BAR)(uint32_t)`](http://cdecl.ridiculousfish.com/?q=int*+%28*CREATE_BAR%29%28uint32_t%29) – Jonathan Mee Jun 14 '16 at 21:37

2 Answers2

3

It's a function pointer type named CREATE_BAR which accepts a uint32_t argument and returns a Foo*. It could hold a pointer to any such function.

2

It is a type for a pointer on function returning Foo*, and taking uint32_t

In c++11, it would be

using CREATE_BAR = Foo* (*)(uint32_t);
Jarod42
  • 203,559
  • 14
  • 181
  • 302