Reputation: 15
I am trying compile an application which showing the error in the following line
enum ROUTE_STATE
{
ROUTE_STATE_DOWN = 0,
ROUTE_STATE_UP = 1,
ROUTE_STATE_STANDBY = 2,
ROUTE_STATE_DISABLED= 4
};
There are four error messages, respectively
enum ": missing tag name
Syntax error: "constant
Syntax error: missing ";" (before "{")
"{" : missing function title (is it an older form table?)
which is in following code
namespace ECON
{
namespace FDC
{
enum ROUTE_TYPE
{
ROUTE_TYPE_RX = 0,
ROUTE_TYPE_TX = 1
};
enum ROUTE_STATE
{
ROUTE_STATE_DOWN = 0,
ROUTE_STATE_UP = 1,
ROUTE_STATE_STANDBY = 2,
ROUTE_STATE_FREE = 3,
ROUTE_STATE_DISABLED = 4
};
}
}
The problem could not be located based on four error messages,Ask for help,thanks
Upvotes: 1
Views: 434
Reputation: 20141
Elaborating the guess of Retired Ninja (which I agree with):
Macros can be a plague, especially in C++ because they don't consider any namespace.
There is nothing wrong in OP's exposed code. So, the reason must be somewhere in the non-exposed.
Imagine that there is somewhere a macro defined
#define ROUTE_STATE "free"
or
#define ROUTE_STATE 2
This would transform
enum ROUTE_STATE {
to
enum "free" {
or
enum 2 {
What a mess.
How to handle this?
You can run the compiler in pre-processing-only mode. E.g. g++
has an option -E
for this, other C++ compilers provide such option as well (but may be with different name). This provides the source code after pre-processing and uncovers such things to the author.
There are conventions (styles) for naming of identifiers which help to lower the risk of such confusions. So, macros should be named in capitals only but any other identifier not. E.g. I prefer
There are a variety of style-guides but most of them are common concerning macros in capitals only and the rest not. (There must be a reason for this.)
May be, it's worth to mention that some of the even widespread APIs like win32 doesn't conform to this simple but valuable rule. (And once, this caused me head-aches until I found the reason.)
Upvotes: 2