Mail Archives: djgpp/1999/08/12/18:18:03
It really shouldn't be too tough for you to copy/import/whatever short code
into an email message now, rather than attach it (?). Anyway....
On 11 Aug 99, difman was found to have commented thusly:
> I tried to compile my program using djgpp in RHIDE, but it gives errors
> like Error: 'FILE' undeclared (first use in function) and 'x' undeclared
> (first use in function) even though i have declared them in the function.
> it also gives Error: 'EOF' undeclared whats the deal?
>
Your code which you attached:
======================================
#include <stdlib.h>
main(void)
{
FILE *text;
char filename[10];
char mytext[1000];
int x = 0;
int y = 0;
printf("Enter name of file: ");
gets(filename, 80);
text = fopen(filename, "r");
while(mytext[x] != EOF) {
x++;
}
while(y != x/2) {
mytext[y] = fgetc(filename);
putchar(mytext[y]);
y++;
}
fclose(*text);
return 0;
}
=================================
This is the list of errors and warnings the compiler produced within RHide
using my particular settings:
(5) Warning: return-type defaults to `int'
(6) Error: `FILE' undeclared (first use in this function)
(6) Error: (Each undeclared identifier is reported only once
(6) Error: for each function it appears in.)
(6) Error: `text' undeclared (first use in this function)
(6) Warning: statement with no effect
(7) Error: parse error before `char'
(12) Warning: implicit declaration of function `printf'
(13) Warning: implicit declaration of function `gets'
(13) Error: `filename' undeclared (first use in this function)
(14) Warning: implicit declaration of function `fopen'
(15) Error: `mytext' undeclared (first use in this function)
(15) Error: `x' undeclared (first use in this function)
(15) Error: `EOF' undeclared (first use in this function)
(18) Error: `y' undeclared (first use in this function)
(19) Warning: implicit declaration of function `fgetc'
(20) Warning: implicit declaration of function `putchar'
(23) Warning: implicit declaration of function `fclose'
But there are even more serious flaws that are not revealed by the compiler,
namely serious errors in logic such as the while { } loop for an uninitialized
array in which the conditional test will always fail. Probably you want to
visit the C language group first and get questions regarding use of C answered
there. They can tell you things about the reserved words, as well as the
functions of the standard C library, and the headers included for certain
functions.
This is also probably a good time to make sure that you not only deal with
compiler error messages, but also compiler *warning* messages, because lots of
programs crash or have unintended/undefined effects and they wouldn't if the
programmer dealt with the 98% of the warning messages that the compiler
produces. Indeed, you have the option of treating warnings as errors if you
check 'pedantic-errors' below.
Below is my own list of compiler warning messages I like to see in general. If
you go to Options->Compiler->Warnings in RHide, and make sure the following
warnings are checked at the very least, you can probably eliminate most
aggravating crashes that occur at run-time. By the way, you need to check the
-O option in Options->Compiler->Optimizations if you want to get warnings about
uninitialized variables, a big source of problems. The only warnings I am
ignoring routinely are the "passing arg # as signed/unsigned due to prototype";
all the others should really be corrected and eliminated. (Btw, I welcome
comments from others as to whether my warning list is too little or too much.)
RHide warning message options:
[ ] -pedantic
[ ] -pedantic-errors
[ ] -w
[x] -W
[ ] -Waggregate-return
[x] -Wall
[x] -Wbad-function-cast
[x] -Wcast-align
[x] -Wcast-qual
[ ] -Wchar-subscripts
[x] -Wcomment
[x] -Wconversion
[ ] -Wenum-clash
[ ] -Werror
[x] -Wformat
[ ] -Wid-clash-
[ ] -Wimplicit
[ ] -Winline
[ ] -Wlarger-than-
[x] -Wmissing-declarations
[x] -Wmissing-prototypes
[x] -Wnested-externs
[ ] -Wno-import
[ ] -Woverloaded-virtual
[x] -Wparentheses
[x] -Wpointer-arith
[x] -Wredundant-decls
[ ] -Wreorder
[x] -Wreturn-type
[x] -Wshadow
[x] -Wstrict-prototypes
[ ] -Wswitch
[ ] -Wsynth
[ ] -Wtemplate-debugging
[x] -Wtraditional
[ ] -Wtrigraphs
[x] -Wuninitialized
[x] -Wunused
[x] -Wwrite-strings
Mitch Halloran
Research (Bio)chemist
Duzen Laboratories Group
Ankara TURKEY
- Raw text -