[GCC-XML] Forward declarations

Brad King brad.king at kitware.com
Wed Jun 16 22:24:27 EDT 2004

Fraser Hanson wrote:
> gccxml by default doesn't seem to work when the C source includes 
> forward declarations.  After some googling and playing with the command 
> line options, I can't seem to find a solution to this.  How can I make 
> this work?
> [fraser at albus:~/work]$ cat test.c
> /* static forward declaration */
> static char* a;
> static char* a = 0;
> [fraser at albus:~/work]$ gcc-2.95 -c test.c
> [fraser at albus:~/work]$ gcc-3.3 -c test.c
> [fraser at albus:~/work]$ gccxml test.c
> test.c:3: error: redefinition of `char*a'
> test.c:2: error: `char*a' previously declared here

$ g++-3.3 -c test.c
test.c:2: error: redefinition of `char*a'
test.c:1: error: `char*a' previously declared here

GCC-XML is intended for C++ and always uses the C++ parser from GCC no 
matter the file extension given.  In fact it is written as an extension 
to the C++ parser and therefore cannot work with the C parser.  The 
C++98 standard in paragraph 7.1.1/7 indicates that the compiler is 
correct to issue this error.

In your example, the "static char* a;" line is not actually a forward 
declaration.  The C99 standard in paragraph 6.9.2/2 refers to this as a 
"tentative definition".  It is sufficient to produce a symbol with 
internal linkage initialized to a NULL-pointer value.  The second line 
with the initialization is a full definition.  The C++98 standard states 
in annex paragraph C.1.2/1 that C++ does not have "tentative definitions".

Unfortunately there does not seem to be a solution to your problem other 
than modifying the source to be C++ or GCC-XML aware using the preprocessor.


More information about the gccxml mailing list