Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: previous de...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 13 Topic 26048 of 26977
Post > Topic >>

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

by Nick Keighley <nick_keighley_nospam@[EMAIL PROTECTED] > May 6, 2008 at 02:21 AM

On 6 May, 03:33, "Michael.Z" <zhangqiuy...@[EMAIL PROTECTED]
> wrote:
> Hi Flash Gordon:

> The Table.c was required to be implemented as generic type.

I'm not sure what a "generic type" is and I have been programming
for quite a while.

>=A0If 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.

It may be you trying to hide implementation details from users
of your code. The outside world uses a void* and your
code (the library) casts it to the right type before use.
This is good. The internal data structure can change
without causing a recompile of the user code.

/* pippo.h */
typedef void* Table_handle;
Table_handle create();
void befunge (Table_handle);

/* pippo.c */
void befunge (Table_handle handle)
{
   Table* table =3D (Table*)handle;
   ...
}

/* user.c */
int main (void)
{
    Table_handle* my_table;
    my_table =3D create();
    befunge(my_table);
    return 0;
}

The point is I *don't* try and have two differing
definitions of Table.


> 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:

so he had two different types didn't he?


> /* Header file List.h*/
> #ifndef LIST_H
> #define LIST_H
>
> #include "bool.h"
>
> =A0 =A0 =A0 =A0 typedef void * List ;
> =A0 =A0 =A0 =A0 typedef void * DataL ;
> =A0 =A0 =A0 =A0 typedef void * ListIt ;
>
> =A0 =A0 =A0 =A0 List makeList ( int , void * (*copy)() , void (*free)()
) =
;
> =A0 =A0 =A0 =A0 void freeList ( List ) ;
> =A0 =A0 =A0 =A0 void clearList ( List ) ;
>
> =A0 =A0 =A0 =A0 boolean accessList ( List , DataL , int ) ;
> =A0 =A0 =A0 =A0 int lengthList ( List ) ;
>
> =A0 =A0 =A0 =A0 boolean accessHead ( List , DataL ) ;
> =A0 =A0 =A0 =A0 boolean insertHead ( List , DataL ) ;
> =A0 =A0 =A0 =A0 boolean deleteHead ( List , DataL ) ;
>
> =A0 =A0 =A0/* not all the header file is copied here*/
>
> /* List.c */
>
> #include "bool.h"
> #include <stdio.h>
> #include <stdlib.h>
>
> #ifndef DATA
> #define DATA
> typedef void * Data ;
> #endif
>
> typedef struct ListNode {
> =A0 =A0 =A0 =A0 struct ListNode * next ; =A0 =A0 =A0 =A0/* reference to
fo=
llowing ListNode */
> =A0 =A0 =A0 =A0 struct ListNode * previous ; =A0 =A0/* reference to
preced=
ing ListNode */
> =A0 =A0 =A0 =A0 Data dptr ;
>
> } ListNode ;
>
> typedef struct List {
> =A0 =A0 =A0 =A0 ListNode * head ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Head
end =
of List =A0 =A0 =A0 =A0 =A0 =A0 */
> =A0 =A0 =A0 =A0 ListNode * tail ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Tail
end =
of List =A0 =A0 =A0 =A0 =A0 =A0 */
> =A0 =A0 =A0 =A0 int _lengthList ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* number
of=
 items within List =A0*/
> =A0 =A0 =A0 =A0 int _sizeData ; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* byte
si=
ze of data to be stored */
> =A0 =A0 =A0 =A0 void (*_freeData)( ) ; =A0 =A0 =A0 =A0 =A0/* returns
data =
item to heap =A0 =A0*/
> =A0 =A0 =A0 =A0 void * (*_copyData)( ) ; =A0 =A0 =A0 =A0/* copies data
ite=
m to another =A0*/
>
> } * List ;

arg!!!

don't top post. Please put your reply after the text you are
replying to.


> On May 3, 2:32 am, Flash Gordon <s...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > Michael.Z wrote, On 03/05/08 08:22:
>
> > > Anyone who can help:
>
> > > Given a Table.h file I am writing a Table.c file.
> > > I keep getting the compile error:
>
> > > previous declaration of Table was here / =A0conflicting types for
>
> > > I think the problem was the result of two pieces of code.
> > > First:typedefstruct Table; =A0/* in Table.c*/
>
> > This says that Table is a struct.
>
> > > Second: struct Table { /*struct definition */ } =A0*Table; =A0/* in
> > > Table.h */
>
> > This says it is a pointer to a struct, that is what the * means.
>
> > > How can I solve the problems?
>
> > By not providing different definitions.
>
> > > Here are the two files
>
> > <snip>
>
> > >typedefvoid * Table ;
>
> > This is not what you said you had and is defining table as yet another
t=
ype.
>
> > <snip>
>
> > >typedefstruct Table{
> > > =A0 =A0 int sizeTable;
> > > =A0 =A0 unsigned sizeData;
> > > =A0 =A0 int (*diff)();
> > > =A0 =A0 unsigned (*hash)();
> > > =A0 =A0 void *(*copy)();
> > > =A0 =A0 void (*free)();
> > > } * Table;
>
> > This is what you said. However pointers to void and pointers to
structs
> > are different things for the simple reason that void and struct are
> > different.
>
> > Also hiding pointers behind atypedefis generally considered a bad
thing.=

> > --
> > Flash Gordon-

don't quote sigs (the bit after the "-- ")


--
Nick Keighley
 




 13 Posts in Topic:
previous declaration of Table was here / conflicting types for
"Michael.Z" <  2008-05-03 00:22:21 
Re: previous declaration of Table was here / conflicting types
ade ishs <no-spam@[EMA  2008-05-03 19:34:39 
Re: previous declaration of Table was here / conflicting types
Flash Gordon <spam@[EM  2008-05-03 10:32:51 
Re: previous declaration of Table was here / conflicting types f
"Michael.Z" <  2008-05-05 19:33:26 
Re: previous declaration of Table was here / conflicting types f
Nick Keighley <nick_ke  2008-05-06 02:21:25 
Re: previous declaration of Table was here / conflicting types f
Ben Bacarisse <ben.use  2008-05-06 12:32:13 
Re: previous declaration of Table was here / conflicting types f
"Michael.Z" <  2008-05-07 01:05:08 
Re: previous declaration of Table was here / conflicting types f
Flash Gordon <spam@[EM  2008-05-07 19:14:36 
Re: previous declaration of Table was here / conflicting types f
CBFalconer <cbfalconer  2008-05-07 12:01:43 
Re: previous declaration of Table was here / conflicting types f
"Michael.Zhang"  2008-05-09 02:40:34 
Re: previous declaration of Table was here / conflicting types f
Chris Torek <nospam@[E  2008-05-10 05:43:46 
Re: previous declaration of Table was here / conflicting types f
Ben Bacarisse <ben.use  2008-05-10 01:19:38 
Re: previous declaration of Table was here / conflicting types f
"Michael.Zhang"  2008-05-10 20:11:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:35:42 CDT 2008.