I have a function getData(void* data)
which should copy to data some internal calculated values
for example int r = getRadius();
r should be copied to data ,and is such a way returned from function getData
what is the correct way to do it?
I tried *(int*)data = r;
but I am not sure this is a best solution.
I have a function getData(void* data) which should copy to data some internal calculated
Share
If you are certain that the memory referenced by the void pointer is an int, then you can be confident in
However a better general solution is:
This way you don’t have to worry about byte alignment or other potential gotchas.