sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) (03/31/89)
Is this an inconsistency ?: struct element { char *key; int level; struct element **fpointer; } struct element *head[LEVELCAP]; /* array of pointers to struct */ Microsoft C 5.1 in MS-DOS compiles this alright, but neither cc nor gcc are able to compile in UNIX 4.1 (or is it 4.2, I can't remember). cc merely gives a "syntax error at or near" the line having the array declaration. gcc, however, complains that "two or more data types in declaration" exist (at the line having the array declaration). Any ideas why? (I think I know why it doesn't work for cc, but I don't know why for gcc). --Raj -- _____________________________________________________________________________ | Disclaimer: I'm just an undergrad. | | All views and opinions are therefore my own. | | | | Rajiv Partha Sarathy sarathy@gpu.utcs.utoronto.ca | | {uunet!attcan mnetor att pyramid}!utgpu!sarathy | |_____________________________________________________________________________|
chris@mimsy.UUCP (Chris Torek) (03/31/89)
In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu> sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) writes: >Is this an inconsistency ?: > 1> struct element { 2> char *key; 3> int level; 4> struct element **fpointer; 5> } 6> struct element *head[LEVELCAP]; /* array of pointers to struct */ > >Microsoft C 5.1 in MS-DOS compiles this alright, but neither cc nor gcc are >able to compile in UNIX 4.1 (or is it 4.2, I can't remember). cc and gcc get gold stars; Microsoft C 5.1 gets a loud raspberry. I have inserted numbers above. Look very closely at line 5 and decide what is missing. Hint: it is a single character that is generally found at the end of a statement or declaration. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
maart@cs.vu.nl (Maarten Litmaath) (04/01/89)
sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) writes:
\Is this an inconsistency ?:
\ struct element {
\ char *key;
\ int level;
\ struct element **fpointer;
\ }
^
add a semicolon here!
\ struct element *head[LEVELCAP]; /* array of pointers to struct */
\Microsoft C 5.1 in MS-DOS compiles this alright, ...
Hahahahahahahahahahahahahahahahaha! Let's rush to the store and buy 5.1!
--
Modeless editors and strong typing: |Maarten Litmaath @ VU Amsterdam:
both for people with weak memories. |maart@cs.vu.nl, mcvax!botter!maart
henry@utzoo.uucp (Henry Spencer) (04/01/89)
In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu> sarathy@gpu.utcs.UUCP (Rajiv Sarathy) writes: > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ You forgot the ";" after the closing "}". In code, such a semicolon is never needed and sometimes will break things. In declarations, the semicolon is absolutely mandatory. Any compiler that *accepts* the above is either being very forgiving or (more likely) is broken. -- Welcome to Mars! Your | Henry Spencer at U of Toronto Zoology passport and visa, comrade? | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
Tim_CDC_Roberts@cup.portal.com (04/01/89)
In <1989Mar30.192903.28426@gpu.utcs.toronto.edu>, Rajiv Sarathy writes: > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ > > cc merely gives a "syntax error at or near" the line having the array > declaration. > > gcc, however, complains that "two or more data types in declaration" exist (at > the line having the array declaration). > > Any ideas why? I know! I know! The Tim Roberts visual unoptimizing C precompiler gives the following error message: struct element { char *key; int level; struct element **fpointer; } ******* ^ Missing Semicolon In Declaration. Probable Havoc Follows. struct element *head[LEVELCAP]; /* array of pointers to struct */ Microsoft C also barfs on this. I suspect that the semicolon got deleted in transition. Tim_CDC_Roberts@cup.portal.com | Control Data... ...!sun!portal!cup.portal.com!tim_cdc_roberts | ...or it will control you.
ark@alice.UUCP (Andrew Koenig) (04/01/89)
In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu>, sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) writes: > Is this an inconsistency ?: > > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ What happens when you put in the missing semicolon? struct element { char *key; int level; struct element **fpointer; }; /* note the semicolon here */ struct element *head[LEVELCAP]; /* array of pointers to struct */ What happens when you put in the missing semicolon? -- --Andrew Koenig ark@europa.att.com
scjones@sdrc.UUCP (Larry Jones) (04/01/89)
In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu>, sarathy@gpu.utcs.toronto.edu (Rajiv Sarathy) writes: > Is this an inconsistency ?: > > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ > > Microsoft C 5.1 in MS-DOS compiles this alright, but neither cc nor gcc are > able to compile in UNIX 4.1 (or is it 4.2, I can't remember). If you look real carefully, you will notice that there's no semicolon after the closing brace of the structure declaration. This is a syntax error that is ignored by some compilers and very badly diagnosed by others. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "When all else fails, read the directions."
w-colinp@microsoft.UUCP (Colin Plumb) (04/01/89)
sarathy@gpu.utcs.UUCP (Rajiv Sarathy) wrote: > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ You forgot the semicolon after the closing brace. It should either be struct element { char *key; int level; struct element **fpointer; }; struct element *head[LEVELCAP]; /* array of pointers to struct */ or struct element { char *key; int level; struct element **fpointer; } *head[LEVELCAP]; /* array of pointers to struct */ The original parses as "struct element struct element *head[LEVELCAP];", which I think you'll agree is a bit hard on a non-AI parser. -- -Colin (uunet!microsoft!w-colinp) "Don't listen to me. I never do." - The Doctor
ftw@masscomp.UUCP (Farrell Woods) (04/03/89)
In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu> sarathy@gpu.utcs.UUCP (Rajiv Sarathy) writes: >Is this an inconsistency ?: > struct element { > char *key; > int level; > struct element **fpointer; > } > struct element *head[LEVELCAP]; /* array of pointers to struct */ >Microsoft C 5.1 in MS-DOS compiles this alright, but neither cc nor gcc are >able to compile in UNIX 4.1 (or is it 4.2, I can't remember). Indeed, you're missing a semi-colon. There are two ways you could declare your array of pointers. The first is to correct your declaration by inserting a semi-colon after the closing brace in your structure template. Another is to leave out the semi-colon, as you've done, and also remove the ``struct element'' on the last line. To wit: struct element { char *key; int level; struct element **fpointer; } *head[LEVELCAP]; /* array of pointers to struct */ -- Farrell T. Woods Voice: (508) 392-2471 Concurrent Computer Corporation Domain: ftw@masscomp.com 1 Technology Way uucp: {backbones}!masscomp!ftw Westford, MA 01886 OS/2: Half an operating system
jon@jonlab.UUCP (Jon H. LaBadie) (04/12/89)
Rajiv's question, and Farrell's response recall painful memories of a similar "bug". In article <15@masscomp.UUCP>, ftw@masscomp.UUCP (Farrell Woods) writes: > In article <1989Mar30.192903.28426@gpu.utcs.toronto.edu> sarathy@gpu.utcs.UUCP (Rajiv Sarathy) writes: > > > struct element { > > char *key; > > int level; > > struct element **fpointer; > > } > > struct element *head[LEVELCAP]; /* array of pointers to struct */ > > Indeed, you're missing a semi-colon. (after the closing brace j.l.) I developed some code for a client with the beginning of the program organized like this: struct foo { ... ... } /* ** ** long ( > 1 page ) preamble of comments ** */ main(...) { ... } On my development machine, the code worked fine and I delivered it and recompiled it on the clients system. The latter had a different cpu. It seemed to run fine ... except that it core dumped when it exited. Ran fine until it exited, just that d****d core file each time you used it. Try to convince someone paying the bill "It works fine, just dumps core each time you use it." Yeah, sure. Took me quite a while to realize main was "trying" to return a 68 byte structure, not an int. Whatever was receiving the return value of main was surely surprised!