"Michael.Z" <zhangqiuyuan@[EMAIL PROTECTED]
> writes:
> The Table.c was required to be implemented as generic type. If I am
> right, Table is declared as void * in header file, the reason is that,
> when used later on, it can be casted to any other type of pointers.
>
> The implementation of Table in Table.c was defined as pointer to
> struct Table, because I need to implement the members of Table.
>
> My professor told us, void * in header indicates a generic type.
> He has some sample codes where List was typedef'd void pointer but the
> definition was struct List Pointer:
First, the more common way to "hide the implementation" is simply to
declare your functions as using a 'struct Table *' (as has already
been explained by Flash Gordon).
Secondly, this does not stop you writing generic functions that have a
'void *' parameter. You can pass a 'struct Table *' where a 'void *'
is expected when is im****tant to do so.
There is no obvious advantage to making the Table generic (in that
sense) rather than simply hidden. In fact there is a positive
*disadvantage* to doing that -- you loose all the type-checking. It
is usually much better to stick with hidden (incomplete) struct
pointers right up to the point where you are *forced* to start using
'void *'.
Your professor may have a reason for doing this, but it does seem like
a wise choice from the sample you posted.
--
Ben.


|