c - typecasting in threads code -


https://computing.llnl.gov/tutorials/pthreads/samples/join.c

i looking @ pthreads code @ link above.

i not able understand type casting being done in code above variable t , status in busywork , main methods.

from man pages pthread_exit:

the value pointed retval should not located on calling thread's stack, since contents of stack undefined after thread terminates.

so guess type casting in example trying avoid referring memory on stack of thread has terminated. find typecasting quite inconvenient , bizzare. can explain?

when create thread pthread_create, argument limited sizeof(void *), use pass pointer struct or other data may bigger size of argument.

in example, argument long t have size smaller sizeof(void *), can pass argument directly pthread_create() call.

the explicit cast made ensure if there difference between memory allocated type (long) or type (void *), fixed compiler.

in practice, cast nothing in platform, cannot guarantee that, must explicit cast argument correct type before using it.

resuming: example using type void * type long, , not literal pointer, variable status not dereference anything.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -