mitchemt@silver.bacs.indiana.edu (09/23/88)
This is an extension of the first note I sent. I need to find out what is wrong with the program listed in the note "Help" from mitchemt. I get the following errors: line 13: warning: illegal combination of pointer and integer, operation = line 19: redeclaration of newstrel line 22: warning: illegal combination of pointer and integer, op RETURN Any help getting rid of these errors would be welcome. The program is being compiled on the Ultrix C compiler on a vax. THANKS, TM
cochrane@spot.Colorado.EDU (COCHRANE JIM T) (09/23/88)
/* You missed two things, noted below in comments. */ struct string { char content; struct string *next; }; typedef struct string STRING; main() { STRING *stringptr; STRING *newstrptr; STRING *newstrel(); /* newstrel needs to be declared; otherwise */ /* it's assumed to return an int. */ newstrptr = newstrel(newstrptr); (*newstrptr).content = 'a'; } STRING *newstrel(sptr) /* '*' added */ STRING *sptr; { sptr = ( STRING * ) malloc (sizeof(STRING)); return sptr; }
brian@radio.uucp (Brian Glendenning) (09/23/88)
In article <9600002@silver>, mitchemt@silver writes: > >line 13: warning: illegal combination of pointer and integer, operation = >line 19: redeclaration of newstrel >line 22: warning: illegal combination of pointer and integer, op RETURN > >Any help getting rid of these errors would be welcome. It looks like you haven't declared a function, thus it defaults to integer when you really want it to be returning a pointer. For example: *** Shell output *** radio<10>cat test.c main(){ char *c_ptr; c_ptr = myfunc(); } char *myfunc() { return (char *)0; } radio<11>cc test.c "test.c", line 4: warning: illegal combination of pointer and integer, op = "test.c", line 8: redeclaration of myfunc "test.c", line 9: warning: illegal combination of pointer and integer, op RETURN radio<12>cat test2.c main() { char *c_ptr; char *myfunc(); c_ptr = myfunc(); } char *myfunc() { return (char *)0; } radio<13>cc test2.c radio<14> *** End output *** -- Brian Glendenning - Radio astronomy, University of Toronto brian@radio.astro.toronto.edu uunet!utai!radio!brian glendenn@utorphys.bitnet
andre@targon.UUCP (andre) (09/26/88)
In article <9600002@silver> mitchemt@silver.bacs.indiana.edu writes: > >This is an extension of the first note I sent. I need to find out what is wrong with the program listed in the note "Help" from mitchemt. I get the following >errors: > >line 13: warning: illegal combination of pointer and integer, operation = You didn't give a prototype of the function newstrel, so it will be seen as an integer function, the default. To fix this you should put a line like STRING *newstrel(); before main. >line 19: redeclaration of newstrel The compiler thought it was an integer functions and now you tell it otherwise. >line 22: warning: illegal combination of pointer and integer, op RETURN Same as previuos problem. If you change this the program has another bug: the argument to newstrel is a STRING *, and not a STRING **. The function first assinges the pointer to where your argument poins to, probably infinity. On very tolerant systems the assignment in main will correct this if you didn't hit your text-space :-). the solution is to get rid of the argument new-pointer = newstrel(); or to make the argument a STRING **; (void) newstrel(&new-pointer); STRING *newstrel (ptr) STRING **ptr; { *ptr = malloc.... return *ptr; } ~----~ |m AAA DDDD It's not the kill, but the thrill of the chase. ~|d1|~@-- AA AAvv vvDD DD Segment registers are for worms. ~----~ & AAAAAAAvv vvDD DD ~~~~~~ -- AAA AAAvvvDDDDDD Andre van Dalen, uunet!mcvax!targon!andre -- ~----~ |m AAA DDDD It's not the kill, but the thrill of the chase. ~|d1|~@-- AA AAvv vvDD DD Segment registers are for worms. ~----~ & AAAAAAAvv vvDD DD ~~~~~~ -- AAA AAAvvvDDDDDD Andre van Dalen, uunet!mcvax!targon!andre