how to get the function pointer to a function in C?

ratzip

I have a function in C:

void start_fun()
{
   // do something
}

I want to use pthread_create() to create a thread and the start routine is start_fun(), without modifing void start_fun(), how to get the function pointer to start_fun();

Lundin

If you write the function name start_fun without any parameters anywhere in your code, you will get a function pointer to that function.

However pthread_create expects a function of the format void* func (void*).

If rewriting the function isn't an option, you'll have to write a wrapper:

void* call_start_fun (void* dummy)
{
  (void)dummy;

  start_fun();

  return 0;
}

then pass call_start_fun to pthread_create:

pthread_create(&thread, NULL, call_start_fun, NULL);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get a pointer to a C function?

From Dev

How to get a general function pointer as a private member of a C++ class?

From Dev

C++ How to get a void pointer to a lambda function?

From Dev

How to get a general function pointer as a private member of a C++ class?

From Dev

Get sizeof a void (*)() function pointer in C

From Dev

How to distinguish if a function pointer in C points to function 1 or function 2

From Dev

How to get address pointer of a member function

From Dev

How to get back pointer of pointers from a function

From Dev

How to get a pointer on the return value of a function?

From Dev

Add to function pointer, to get pointer to another function?

From Dev

Add to function pointer, to get pointer to another function?

From Dev

Pointer to function pointer in C++

From Dev

How to rewrite this function into a pointer in c++?

From Dev

How to create a "typedef to a function pointer" in C#?

From Dev

how to keep a struct pointer outside a function in C

From Dev

How to create a thread of a pointer to a function C++

From Dev

How to print values of function pointer in C?

From Dev

how to keep a struct pointer outside a function in C

From Dev

How to create a thread of a pointer to a function C++

From Dev

C++ pointer to member function not a function pointer

From Dev

How to return a pointer from a function to a pointer, C Language

From Dev

C Function Pointer Mishap

From Dev

C: Function pointer

From Dev

Pointer to a function in C#

From Dev

Initializing a function pointer in C

From Dev

Writing a function pointer in c

From Dev

typedef and pointer to function in C

From Dev

function pointer C programming

From Dev

function pointer in c - understanding

Related Related

HotTag

Archive