开发者

set int of a struct from a memory buffer

开发者 https://www.devze.com 2023-04-11 17:35 出处:网络
I have more of a cosmetic question: I have a memory stream (void *) which i use in the sample as \"cur_ptr\".

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

精彩评论

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