s********k 发帖数: 6180 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: silverhawk (silverhawk), 信区: Programming
标 题: One question about Void pointer
发信站: BBS 未名空间站 (Mon Mar 28 10:32:50 2011, 美东)
Is it risk to use void pointer in the following case:
typedef struct
{
void *next;
UINT16 xx;
UINT16 yy;
byte zz;
} a;
mostly, I think
struct a
{
struct a *next;
UINT16 xx;
UINT16 yy;
byte zz;
};
could be better, but is there any risk to use void pointer? what we should
pay attention in order to carefully manipulate the pointer in this case?
thanks | c********1 发帖数: 161 | 2 For me, I prefer the second one if your idea is to create a kind of linked
list whose "next" pointer points to the next element of the same data
structure. And this should be safe.
For the void pointer, it just means a pointer pointing to a void type. So
you may have to define how large you have to allocate memory for "next" to
point to and you may need to do some necessary type casting.
So, it really depends on your program. |
|