Problem wth <sys/utsname.h> amd g++
807575Dec 21 2007 — edited Dec 22 2007I was compiling the open source program xtide which is set up for gcc/g++. It compiles cleanly until I get to the file xttpd.cc which produces the following error:
----------------------------------------------
xttpd.cc:99: error: expected `;' before "foo"
[...]
----------------------------------------------
Line #99 of the file reads:
----------------------------------------------
utsname foo;
----------------------------------------------
I though that there must be some problem with the declaration of utsname in /usr/include/sys/utsname.h. I compiles the file using the -E flag, inspected the preprocessor output and found the following lines from the include file:
----------------------------------------------
# 1 "/usr/include/sys/utsname.h" 1 3 4
# 16 "/usr/include/sys/utsname.h" 3 4
#pragma ident "@(#)utsname.h 1.30 04/09/28 SMI"
extern "C" {
# 34 "/usr/include/sys/utsname.h" 3 4
struct utsname {
char sysname[257];
char nodename[257];
char release[257];
char version[257];
char machine[257];
};
extern struct utsname utsname;
# 108 "/usr/include/sys/utsname.h" 3 4
extern int uname(struct utsname *);
# 123 "/usr/include/sys/utsname.h" 3 4
}
----------------------------------------------
Notice the line: extern struct utsname utsname;
I thought that this might somehow be polluting the C++ name space, so I
deleted it from the preprocessor output and then the file compiled just fine.
So my question is whether there is a general problem with a declaration like this in conjunction with C++ or whether this is a problem unique to g++? (I haven't gotten far enough along in getting this to compile with Studio 12 to see if it will also have a similar problem.)
I'm also confused by the error message. Is g++ expecting a semi-colon because it see the "utsname" in "utsname foo" as an instantiation of a struct and not a type declaration for foo.
Regards,
--
Jeffery Small