R
Rouben Rostamian
I ran into a few questionable C programming practices while reading
a very nice tutorial on pthreads in:
http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads
For instance, in several places we have code similar to the following:
------------------------------
#include <stdio.h>
void foo(void *arg)
{
printf("the number is %d\n", arg);
}
int main(void)
{
int i;
for (i=0; i<5; i++)
foo((void *)i);
return 0;
}
------------------------------
Is there any way that one can justify the cast from int to (void *)
and back? Probably the printf() statement can be made a bit more
digestible with an additional cast, as in:
printf("the number is %d\n", (int)arg);
but even then, the whole effort looks suspicious.
Elsewhere in the same web page we have:
int status;
...
bar((void **)&status);
which in effect is a variation on the previous theme.
a very nice tutorial on pthreads in:
http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads
For instance, in several places we have code similar to the following:
------------------------------
#include <stdio.h>
void foo(void *arg)
{
printf("the number is %d\n", arg);
}
int main(void)
{
int i;
for (i=0; i<5; i++)
foo((void *)i);
return 0;
}
------------------------------
Is there any way that one can justify the cast from int to (void *)
and back? Probably the printf() statement can be made a bit more
digestible with an additional cast, as in:
printf("the number is %d\n", (int)arg);
but even then, the whole effort looks suspicious.
Elsewhere in the same web page we have:
int status;
...
bar((void **)&status);
which in effect is a variation on the previous theme.