MisterE said:
Which is 'correct':
void foo(void *a)
{
int *b = (int *)a;
}
or
void foo(void *a)
{
int *b = a;
}
Both are "correct". The second is generally considered better style
since it's less to type, less to read and comprehend, and there are
situations where unnecessary casts can disguise errors. It's best to
save casts for where they must be used, so they also act as an added
warning to the user that "something a bit special is going on here".
Is there any reason why most source code listings almost always use the
first one?
I don't accept the premise - most C code I've seen uses the second form
and I'd be very surprised if most C code used the first. If some people
use it habitually in C, I can only imagine it's because they don't
understand the concept and purpose of C void pointers very well.