Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

va_list has not been declared

Tags:

When compiling some working code on Fedora 11, I am getting this error:

/usr/include/c++/4.4.1/cstdarg:56: error: ‘::va_list’ has not been declared 

I am using:

[doriad@davedesktop VTK]$ g++ --version g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2) 

Does anyone know what the problem could be?

like image 926
David Doria Avatar asked Mar 02 '10 15:03

David Doria


People also ask

Which header file contains Va_list?

h header file to extract the values stored in the variable argument list--va_start, which initializes the list, va_arg, which returns the next argument in the list, and va_end, which cleans up the variable argument list.

What is a Va_list?

va_list is a complete object type suitable for holding the information needed by the macros va_start, va_copy, va_arg, and va_end. If a va_list instance is created, passed to another function, and used via va_arg in that function, then any subsequent use in the calling function should be preceded by a call to va_end.


2 Answers

I had the same error message and I solved including one of the next files

#include <stdarg.h> 

or

#include <cstdarg> 
like image 84
Oscar Raig Colon Avatar answered Sep 29 '22 07:09

Oscar Raig Colon


Bringing in the varadic macro set in g++ 4.4 has confusing and twisted semantics. You might get a better idea of what isn't happening by using g++ -E broken_code.cpp and looking at what the pre-processor is bringing in. There are a few dozen GNU C preprocessor directives that could prevent the ::va_list declaration from compiling as __gnuc_va_list which itself is of type __builtin_va_list

The junk code:

$cat junk.cpp #include <cstdarg>  void foo(char *f, ...) { va_list va; va_start(va, va); } int main(void) { foo("", "", ""); return 0; } $ g++ junk.cpp $ g++ --version g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1 

compiles and links (with warnings) with the relevant output of g++ -E junk.cpp being:

# 40 "/usr/lib/gcc/i486-linux-gnu/4.4.1/include/stdarg.h" 3 4 typedef __builtin_va_list __gnuc_va_list; # 102 "/usr/lib/gcc/i486-linux-gnu/4.4.1/include/stdarg.h" 3 4 typedef __gnuc_va_list va_list; # 45 "/usr/include/c++/4.4/cstdarg" 2 3 # 54 "/usr/include/c++/4.4/cstdarg" 3 namespace std __attribute__ ((__visibility__ ("default"))) {    using ::va_list;  } 
like image 21
msw Avatar answered Sep 29 '22 06:09

msw