简体   繁体   中英

In C, when using the name of the function in pthread_create is it the same as using a reference?

I'm not sure if I said it right.

   pthread_create(..., ..., &some, ...);
   ...is the same as:
   pthread_create(..., ..., some, ...);

I'm learning threads, if you could give a website or a video that makes it really simple, it would be great. Threads - locks, condition variables, etc. Thanks!

Yes because function name is pointing to a memory location . In simple words it is a memory address, so you pass it like foo or &foo , both are the same.

Example Code:

#include <stdio.h>

int foo(){

    printf("hello world");

}

int (*fuu)();

int main (void)
{
   fuu = foo;
   fuu();

    return 0;
}

Hope this helps

You can use both function name some or pointer to function &some to get the address of the function.

Check also this answer .

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