Pranab Mehta wrote:[color=blue]
>
> Hi All,
>
> I apologize if this has been brought up here before.
> Searching through the newsgroup I found variants of
> my question, but not exactly what I am thinking about.
>
> If on a given platform, I am guaranteed that:
> sizeof(integer) <= sizeof(void*)
> Is it safe to store an int in a void* and cast it
> back to int without truncating/losing data ?[/color]
Is it "safe?" Yes, because on the great majority of
C implementations it will work as you desire. Is it
"perfectly safe?" No, because the C language Standard
does not specify the result of either conversion, and it
is therefore possible that some C implementation might
not give the desired result.
You must make your own decisions about how much "safety"
your applicaition requires.
[color=blue]
> Secondly, is the minimum size of a void* (or char*),
> defined in the standards or is it entirely platform
> dependant ?[/color]
I'm not sure what you are asking here. No C object
can have a `sizeof' smaller than 1. No non-aggregate
object is required to have a `sizeof' greater than 1.
All the Standard has to say about your question is
1 <= sizeof(void*) && sizeof(void*) == sizeof(char*)
.... and each implementation is free to choose any value
satisfying these constratints.
--
Eric.Sosman@sun.com