0

This question is partially answered here What does "typedef void (*Something)()" mean

But the answer is not completely clear to me.

if I write

typedef void (*task) ();

How does it expand?

thread_pool(unsigned int num_threads, task tbd) {
      for(int i = 0; i < num_threads; ++i) {
        the_pool.push_back(thread(tbd));
      }
    }

Would it look like this?

thread_pool(unsigned int num_threads, (*task) () tbd) {
      for(int i = 0; i < num_threads; ++i) {
        the_pool.push_back(thread(tbd));
      }
    }

Probably not, because it is a syntax error. I hope you can clear things up for me.

Code example is from http://www.thesaguaros.com/openmp-style-constructs-in-c11.html

Community
  • 1
  • 1
Maik Klein
  • 15,548
  • 27
  • 101
  • 197

1 Answers1

2

It's like this:

thread_pool(unsigned int num_threads, void (*tbd) ())

That is, the type is the function signature, the only "word" in which is "void." The typedef name "task" disappears in this example because we aren't using the typedef anymore.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436