Joona I Palaste said:
What's that supposed to mean? I said "will not necessarily work", not
"will never work".
1. A pointer to void can be converted to and from a pointer to
any object type (a function is not an object.)
Whether the converted pointer will be properly aligned for
it to be useful is another question entirely.
2. A pointer to any object type can be converted to a pointer
to character. The resulting character pointer is always
correctly aligned (see 6.3.2.3 (7).)
Since the OP's question involved conversion between "void *" and
"char *", it SHOULD ALWAYS work.
Now, from ISO/IEC 9899
----------------------
6.3.2.3 Pointers
1 A pointer to void may be converted to or from a pointer to
any incomplete or object type. A pointer to any incomplete
or object type may be converted to a pointer to void and
back again; the result shall compare equal to the original
pointer.
7 A pointer to an object or incomplete type may be converted
to a pointer to a different object or incomplete type. If
the resulting pointer is not correctly aligned for the
pointed-to type, the behavior is undefined. Otherwise, when
converted back again, the result shall compare equal to the
original pointer. When a pointer to an object is converted
to a pointer to a character type, the result points to the
lowest addressed byte of the object. Successive increments
of the result, up to the size of the object, yield pointers
to the remaining bytes of the object.
8 A pointer to a function of one type may be converted to a
pointer to a function of another type and back again; the
result shall compare equal to the original pointer. If a
converted pointer is used to call a function whose type is
not compatible with the pointed-to type, the behavior is
undefined.
[The reason I used "malloc" is because of the following. The
emphasis here is on the phrase "suitably aligned."]
7.20.3 Memory management functions
1 ...
The pointer returned if the allocation succeeds is
suitably aligned so that it may be assigned to a
pointer to any type of object and then used to access
such an object or an array of such objects in the space
allocated
...