Mail Archives: djgpp/2001/10/11/23:49:14
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
> <mambuhl AT earthlink DOT net> 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 <stdio.h>
> >>
> >> struct bit {
> >> int bit;
> >> struct bit *next;
> >> }
> >>
> >> main(int argc, char *argv[])
> >> {
> >> int x;
> >> FILE *in, *out;
> >>
> >> if (argc < 3) {
> >> puts("Usage: binprint <numbers> <output>");
> >> 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
- Raw text -