Mail Archives: djgpp/2001/10/09/16:34:16
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. So when I ran the binary with no
arguments, it skipped the argc check and gave me this message:
Error opening input file: TEMP=C:\WINDOWS\TEMP
Not quite right... so I put some test code in, and discovered argc had
a value of 13268 and any strings I attempted to print out magically
turned into environment variables! After I realized that the semicolon
was missing and put it in, it fixed the problems, but obviously the
compiler needs to catch that. Is this a current bug or is it supposed
to act that way? :)
-- Buddy
- Raw text -