Re: previous declaration of Table was here / conflicting types for



[snip: On May 6, 3:32 am, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:
"Michael.Z" <zhangqiuy...@xxxxxxxxx> 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 wastypedef'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 important to do so.

I just want to make sure I got you right.You are suggesting:
typedef struct Table{ ...} Table;
Table * makeTable( void* size, void * data);

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

I don't quit understand this part.
"generic(in that sense)": refers to what I said about my professors
way.
vs
"simply hidden": the above example. Table * makeTable( void* size,
void * data);

is usually much better to stick with hidden (incomplete) struct
pointers right up to the point where you are *forced* to start using
'void *'.


an example of being *forced* would be:

void useTable(*void myTable){
Table * makeTable = (Table *)myTable;

}

if my example is not right, any chance you can give me correct one?




Your professor may have a reason for doing this, but it does seem like
a wise choice from the sample you posted.

--
Ben.

"
.



Relevant Pages

  • Re: void *
    ... struct list_node *next; ... It would probably help if your structure had a member which identified ... That was my understanding of 'void *' concept. ... it guarantees that you can supply pointers to the various data ...
    (comp.lang.c)
  • Re: generic linklist
    ... you can create a list structure that's type-agnostic by using void ... pointers for the list node data and by associating type-aware ... struct glnode *next; ... int cmpStrings (const void *lhs, ...
    (comp.lang.c)
  • Re: Thoughts about the new standard
    ... There is no reason any longer for the distinction. ... and pointers were not as clean as they are now. ... unnecessary to specify whether an object is a struct, ...
    (comp.std.c)
  • Re: legality of forward declaration
    ... struct ForwardDeclared; ... void foo; ... or a bug in gcc and MS compilers ... Arrays and pointers are not the same thing ...
    (comp.lang.c)
  • Re: Is this legal
    ... This is a cut down example of some code I've written to iterate ... typedef void list_function; ... struct generic_list *next; ... between pointers to void and pointers to struct appear valid. ...
    (comp.lang.c)