Steve Pope:
I'm not sure the language requires that an expression like
(char *) pint, where pint is a pointer to int, does the required
conversion.
I think in does. If the Standard doesn't explicitly state this, then it
should.
I believe the Standard says somewhere that "void*" and "char*" must have
identical representation. (Let's forget for the moment that we're not
allowed access multiple members of a union).
union ByteAddress {
void *pv;
char *pc;
};
int i;
ByteAddress n;
n.pv = &i; /* This is definitely OK */
"pc" and "pv" should be identical right now. Therefore, we could do:
int arr[2];
ByteAddress a,b;
a.pv = arr;
b.pv = arr+1;
ptrdiff_t i = b.pc - a.pc;
(Again, I acknowledge that the Standard forbids use of unions in this
fashion.)
Anyway, I digress. If you don't like the following:
(char*)pint
, then I suppose you can write the following instead:
static_cast<char*>( static_cast<void*>(pint) );
(Actually this sounds utterly ridiculous as I write it -- programmers have
been casting to char* in C for decades...)