Jonas Schnelli
Jonas Schnelli

Reputation: 10005

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") 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

Upvotes: 0

Views: 126

Answers (1)

Jaffa
Jaffa

Reputation: 12700

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

*((int*)cur_ptr);

Upvotes: 2

Related Questions