| Keith Thompson 2007-06-18, 10:07 pm |
| Eric Sosman <Eric.Sosman@sun.com> writes:
> Frank Cusack wrote On 06/18/07 12:28,:
>
> And even that won't always work: pthread_t is *really*
> opaque, and need not be a type to which a cast operator can
> be applied. On at least one implementation, pthread_t is
> a struct.
So one approach would be to cast the address of the pthread_t object
to unsigned char*, and use it to print (probably in hexadecimal) the
values of the bytes making up the representation. This won't
necessarily be meaningful, but it could be useful, at least to distinguish
different values.
For example:
#include <stdio.h>
#include <pthread.h>
static void print_raw(void *addr, size_t size)
{
unsigned char *base = addr;
size_t i;
for (i = 0; i < size; i ++) {
printf("%02x", base[i]);
}
}
int main(void)
{
pthread_t self = pthread_self();
fputs("pthread_self() returns ", stdout);
print_raw(&self, sizeof self);
putchar('\n');
return 0;
}
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|