I've been working on an application under Linux using gcc 3.0.2.  It uses a number of standard C functions, among which are the stat() and fstat() functions as defined in <sys/stat.h>.  A friend working under Windows volunteered to help me debug my code and work on future projects with me.  I suggested that he try Dev-C++ because it uses gcc and should be more or less compatible with my environment.

After importing my project into Dev-C++ v4.9.7.0 (5.0 beta 7) with gcc 3.2, we were able to eliminate most of the compilation errors by tweaking project settings and such.  A few are lingering, and we are unable to find their causes.

As soon as I declare a 'struct stat' to hold the return values from either stat() or fstat(), it not only complains that it can't figure out the struct's storage size, but it generates implicit declaration errors for stat(), fstat(), even fileno() which is defined in <stdio.h> and works fine when the 'struct stat' is commented out!

The real kicker is that if I compile under mingw and leave off the '--std=c99' option to compile in C89 mode instead, I don't get these errors.  Unfortunately I've already got a rather large body of code written to the C99 spec that won't compile with this change.

My gcc command line as shown in the Dev-C++ message window is:

gcc testme.c -o testme -I"c:/dev-cpp/include" -std=c99

testme.c contains:

-------------------------8<-------------------------

#include <sys/stat.h>
#include <stdio.h>

int main()
{
    struct stat  filestat;
    FILE         *openfile;
    int          test;

    openfile = fopen("c:\\src\\main.c", "r");

    fstat(fileno(openfile), &filestat);
   
    test = filestat.st_size;

    printf("test = %d\n", test);

    fclose(openfile);

    return 0;
}

---------------------8<---------------------

And, when compiled, yields the following errors:

testme.c: In function `main':
testme.c:6: storage size of `filestat' isn't known
testme.c:12: warning: implicit declaration of function `fstat'
testme.c:12: warning: implicit declaration of function `fileno'

I know it's generally bad to assume that just because a program will build under one compiler, it should build under another, but in this case it's the same compiler!  This works fine in gcc 3.0.2 under Linux (kernel 2.4.19, glibc 2.1, not that it matters), in C89 or C99 mode.  This problem crops up on my friend's Windows XP box and my Linux box running the mingw build tools under WINE (from the command line -- Dev-C++ doesn't work well under WINE).

We've tried everything we can think of.  We started with gcc 2.95.3 in the other beta package (which seems to compile this example), but that had other problems.  Screenfuls of errors on my app.  I tried adding the include/ and lib/ directories to my path.  I'd download an older package, but we're both on dial-up and it takes an hour and a half or so to grab each release.

Has anyone ever seen behavior like this?  Does the test program compile properly?  I'd hate to have him resort to MSVC.

Thanks.

Lime