tags:

views:

115

answers:

2

I'm using Visual Studio 2008 Express Edition to compile the following code in a header file:

bool is_active(widget *w);

widget is defined earlier as,

typedef void widget;

The compiler complains with the error:

>c:\projects\engine\engine\engine.h(451) : error C2061: syntax error : identifier 'is_active'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : ';'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : 'type'

I get similar errors for all other functions returning bool.

NB. The following compiles fine:

void  widget_activate_msg(widget *g,  message *msg);

Why would this give a compiler error?

Some people have requested I post the code - here it is:

Line 449: widget * widget_new_from_resource(int resource_id);
Line 450: void     widget_delete_one(widget *w);
Line 451: bool     is_active(widget *w);

EDIT - this is now fixed:

@BatchyX commented below about whether I was using C or C++. What I didn't know was that Visual C++ 2008 will compile any file by default (but you can override this setting ) with the .c extension as C and those with .cpp as C++. ( the error was caused when compiling a .c file including "Engine.h" ).

+3  A: 

Most likely, something above this line has a syntax error. Did you forget }s or ; after a class declaration ?

Also make sure you are using C++ and not C. C doesn't have a bool type. If you're using C, then use an int instead.

BatchyX
Or even make some typedef + enum for bool (IIRC VC++ doesn't support stdbool.h).
Matteo Italia
@BatchyX - I am using C++. Incidentally, how would Visual C++ 2008 know whether I am using C or C++ - a compiler switch perhaps?
BeeBand
@BatchyX - I discovered that Visual C++ 2008 will compile any files that have the extension .c as C and any with the extension .cpp as C++. You came closest to the answer - in that I was clearly compiling C when I wanted to compile C++.
BeeBand
@BeeBand by default the file suffix (.c or .cpp), but it can be overridden for a single file or an entire project - I think it's under the "Advanced" compiler settings.
Christoffer
@christoffer - thank you.
BeeBand
+2  A: 

I'm guessing that it's not possible to typedef void. Why not use typdef void* WidgetPtr; and then bool is_active(WidgetPtr w);
EDIT: Having done some tests it's clear that void can be typedef'd and it can be part of the function signature as shown in the users code. So the only other solution is that whichever header has declared typedef void Widget is not included within the file that declares/defines the function or you're having a #def guard statement clash.

Vite Falcon
@Vite, it is definitely possible to typedef void.
BeeBand
@BeeBand... yes, found that myself after testing it out :)
Vite Falcon
@Vite, the `typedef void widget` is within the same header file as the function declaration causing the compile error (i.e. "Engine.h")
BeeBand
@BeeBand, can u explain which CPP file is causing this issue? It may not be Engine.cpp that causes this error (i hope). I know the error is shown at Engine.h, but the error actually occurred when it was trying to compile a cpp file.
Vite Falcon