~/tmp/void$ cat test.c
#include <stdio.h>
void test(void *p)
{
        fprintf(stdout,"%d",*(int*)p);
}
int main(void)
{
        int a = 32;
        test((void *)&a);
        return 0;
}
~/tmp/void$ gcc -o test test.c
~/tmp/void$ ./test
32
--------------------------------
指针的强制转化。
 


在2009-11-18,"刘小林" <ziyu...@gmail.com> 写道:
>各位,小弟有一问:如何在自己定义的函数中以void类型的指针作形参,并且还要在该函数中操作传入的参数。
>例如,假设有如下代码段:
>
>-----------------------------
>void test (void * p)
>{
>    //一些包括对传入参数的操作,比如,得到传入的值。
>}
>-----------------------------
>
>>

--~--~---------~--~----~------------~-------~--~----~
 要向邮件组发送邮件,请发到 ph4nt0m@googlegroups.com
 要退订此邮件,请发邮件至 ph4nt0m-unsubscr...@googlegroups.com
-~----------~----~----~----~------~----~------~--~---

回复