开发者

set int of a struct from a memory buffer

I have more of a cosmetic question:

I have a memory stream (void *) which i use in the sample as "cur_ptr". Now i want to read the first bytes into a int ("version") 开发者_Python百科of a struct ("a_struct"). My code that works:

int *version;
version = cur_ptr;
a_struct->version = *version;

How can i write it without the helping pointer *version?

That one won't work:

a_struct->version = (int)*cur_ptr;

any ideas?

Thanks


First cast cur_ptr to int* then get it's value ;)

*((int*)cur_ptr);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜