Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie question: how to compile this program ?

10 views
Skip to first unread message

neoe77

unread,
Jul 15, 2009, 11:27:02 PM7/15/09
to
anyone could please help me out of this:
===================my test c program====================
t1.c

#include <containers.h>
#include <list.h>

typedef struct {
int v;
char s[10];
} MyStruct;
int main(void){
List list= newList(sizeof(MyStruct));
MyStruct data;
int nb = list->lpVtbl->Add(&list,&data);
nb = list->Add(&data);
return 0;
}

==================compiler output====================
C:\lcc\bin>lcc -o a.exe t1.c
Error t1.c: 11 left operand of -> has incompatible type 'struct
_List'
Error t1.c: 11 left operand of -> has incompatible type 'struct
_List'
Error t1.c: 11 found 'struct _List' expected a function
Warning t1.c: 11 missing prototype
Error t1.c: 11 operands of = have illegal types 'int' and 'void'
Error t1.c: 12 left operand of -> has incompatible type 'struct
_List'
Error t1.c: 12 found 'struct _List' expected a function
Warning t1.c: 12 missing prototype
Error t1.c: 12 operands of = have illegal types 'int' and 'void'
7 errors, 2 warnings


=================lcc-win32 stand libary help==================

Function: Add

Synopsis

#include <containers.h>
int (*Add)(List *L1,void *data);

Description

This function adds an element at the end of the given list.

Returns

The number of elements in the list

Example:

List list;
MyStruct data;
int nb = list->lpVtbl->Add(&list,&data);

This simpler syntax is also accepted:

int nb = list->Add(&data);


============
thanks in advance.

Friedrich Dominicus

unread,
Jul 16, 2009, 12:56:55 AM7/16/09
to
neoe77 <neoe...@gmail.com> writes:

This prototyp seems to be wrong it
is List &L1

and list.h contains some other implementation of list (more
traditional C)

what you like to have is

#include <containers.h>


typedef struct {
int v;
char s[10];
} MyStruct;

int main(void){
List list= newList(sizeof(MyStruct));
MyStruct data;

int nb = list.lpVtbl->Add(list,&data);
nb = list.Add(&data);
return 0;
}


However two times &data is probably a very bad idea....

Regards
Friedrich

--
Please remove just-for-news- to reply via e-mail.

jacob navia

unread,
Jul 16, 2009, 3:37:40 AM7/16/09
to
Hi

This is a catastrophic bug in the documentation.

List is an object, not a pointer! That is why the
"->" doesn't work.

Here is a version that compiles cleanly:


#include <containers.h>

typedef struct {
int v;
char s[10];
} MyStruct;
int main(void){
List list= newList(sizeof(MyStruct));
MyStruct data;

// Note the . instead of ->


int nb = list.lpVtbl->Add(list,&data);
nb = list.Add(&data);
return 0;
}

I have updated the documentation eliminating those errors

Sorry about this


0 new messages