From: Jack Klein Newsgroups: comp.os.msdos.djgpp Subject: Re: compiler doesn't catch missing semicolon after struct Message-ID: References: <3BC35FB1 DOT FF1958C AT earthlink DOT net> <1hu8stke235jh08aogbbc44rojtm115j23 AT 4ax DOT com> X-Newsreader: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 68 Date: Fri, 12 Oct 2001 03:43:27 GMT NNTP-Posting-Host: 12.76.49.110 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1002858207 12.76.49.110 (Fri, 12 Oct 2001 03:43:27 GMT) NNTP-Posting-Date: Fri, 12 Oct 2001 03:43:27 GMT Organization: AT&T Worldnet To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Wed, 10 Oct 2001 12:43:57 -0400, Radical NetSurfer wrote in comp.os.msdos.djgpp: Don't top post, it's rude. Fixed. > On Tue, 09 Oct 2001 20:33:27 GMT, Martin Ambuhl > wrote: > > >tenbux wrote: > >> > >> Hi all, > >> > >> I was working on a fairly simple lab for a CS class, and using DJGPP > >> to compile and test my programs. Here is some sample code I had > >> written: > >> > >> #include > >> > >> struct bit { > >> int bit; > >> struct bit *next; > >> } > >> > >> main(int argc, char *argv[]) > >> { > >> int x; > >> FILE *in, *out; > >> > >> if (argc < 3) { > >> puts("Usage: binprint "); > >> return; > >> } > >> > >> if ((in = fopen(argv[1], "r")) == NULL) { > >> printf("Error opening input file: %s\n", argv[1]); > >> return; > >> } > >> > >> You'll notice that there is no semicolon after the struct declaration > >> (as is required). But gcc didn't catch this, instead it warned me > >> about main not being declared as int. > > > >gcc caught it. You declared main as returning a struct bit instead of > >an int. It told you about, but ... > > > >> So when I ran the binary with no > >> arguments, > > > >you ignored the warning and got what you deserved. > > > >> Is this a current bug or is it supposed > >> to act that way? :) > > > >Don't blame the compiler for your errors. > GCC does some very nice Syntax Checking > (more than some compilers do) It's not a syntax error. It's undefined behavior, but syntactically perfectly correct. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq