[GCC-XML] stat and stat64 mystery

Bryan Ischo bji-gccxml at ischo.com
Thu Jul 5 00:51:24 EDT 2007


Hey all.  I'm trying to understand a failure I am getting with some code
that I am using in conjunction with gccxml.

The problem I am having is that gccxml, when parsing
/usr/include/sys/stat.h on a Linux system (I have tried this on a variety
of RedHat Linux distributions from RedHat 9 to Fedora Core 5), reports on
two structs called "stat" and "stat64", which are themselves defined in
the file /usr/include/bits/stat.h, included by /usr/include/sys/stat.h.

When I inspect the bits/stat.h file I do indeed see these structure
definitions:

struct stat
  {
      [fields omitted]
  };

#ifdef __USE_LARGEFILE64
struct stat64
  {
      [fields omitted]
  };
#endif

But the problem is, if I try to compile C++ code which references the
types "stat" or "stat64", I get an error.  For example, when compiling
this file:

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

static stat a_stat;
static stat64 a_stat64;
-----------------------------------

GCC gives these errors:

bji$ g++ -c foo.cpp
foo.cpp:3: error: 'stat' does not name a type
foo.cpp:4: error: 'stat64' does not name a type


Of course, I can make the problem go away if I instead use:

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

static struct stat a_stat;
static struct stat64 a_stat64;
-----------------------------------

What I don't understand is, why gcc requires these to be referenced as
"struct stat" and "struct stat64".  I thought that in C++, structs are
automatically typedef'd to a type of the same name?  This file certainly
compiled fine using g++:

-----------------------------------
struct stat
{
    int a;
};

struct stat64
{
    int b;
};

static stat a_stat;
static stat64 a_stat64;
-----------------------------------

What I really don't understand is, how the code being included by
<sys/stat.h> can be defining structs stat and stat64 that do *not* have
implicit typedefs so that the types can be referenced as simply "stat" and
"stat64".

I realize this is not a gccxml problem per se, and I will take this to the
gcc list if that's what's best, but I thought that someone here might have
some idea of what's going on.

Thank you!
Bryan

------------------------------------------------------------------------
Bryan Ischo                bryan at ischo.com            2001 Mazda 626 GLX
Hamilton, New Zealand      http://www.ischo.com     RedHat Fedora Core 5
------------------------------------------------------------------------





More information about the gccxml mailing list