blargg said:
(e-mail address removed) wrote: ....
Debatable; having to cast means having to intentionally convert the
pointer type, while using void* means it gets converted to whatever
pointer type is needed, even if you didn't realize the type it was
converting to.
So let me get this straight:
enum inttype {SCHAR, SHORT, INT, LONG, LLONG};
int void_func(void* pv, enum inttype code)
{
switch(code)
{
case SCHAR:
signed char * psc = pv;
*psc = 42;
break;
// etc. for the other codes.
}
}
intptr_t caller()
{
intpt_t n;
void_func(&l, LONG);
return n;
}
Is less safe than:
enum inttype {SCHAR, SHORT, INT, LONG};
int void_func(char* pv, enum inttype code)
{
switch(code)
{
case SCHAR:
signed char * psc = (signed char*)pv;
*psc = 42;
break;
// etc. for the other codes.
}
}
intptr_t caller()
{
intptr_t n;
char_func((char*)&l, LONG);
return n;
}
How exactly is the greater safety of the second form achieved? In
particular, how would it make it any easier for the user to find out
if he's made a mistaken assumption about what intprt_t is?