"comma at end of enumerator list" error due to macros in libqof
Tim M
tim at filmchicago.org
Mon Jun 6 02:10:08 EDT 2011
Hello,
Per my previous email I am looking at compiler warnings/errors and I
found an interesting one for which I could use some advice. During
make, libqof came up with a fairly large number of errors, including
quite a few "comma at end of enumerator list" errors. Some of the
errors were quite simple to fix because they were simple enum lists
with a comma after the last enum item. Of course, remove the extra
comma and voila - no more error.
It took me a little time to decipher the same compiler error for this
line, however:
DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST)
After a little research, I found that basically, the enum list is
defined in a macro:
#define LOG_LEVEL_LIST(_) \
_(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR) \
_(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \
_(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \
_(QOF_LOG_MESSAGE, = G_LOG_LEVEL_MESSAGE) \
_(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)
The DEFINE_ENUM macro then looks like this:
#define DEFINE_ENUM(name, list) \
typedef enum { \
list(ENUM_BODY) \
}name;
So DEFINE_ENUM in turn calls LOG_LEVEL_LIST(ENUM_BODY). ENUM_BODY
looks like this:
#define ENUM_BODY(name, value) \
name value,
ENUM_BODY then expands to "name value," for every entry in
LOG_LEVEL_LIST. This then causes the "comma at end of enumerator list"
error mentioned at top because the enum generated by this macro
combination always has a comma after the last entry:
typedef enum {
QOF_LOG_FATAL = G_LOG_LEVEL_ERROR,
QOF_LOG_ERROR = G_LOG_LEVEL_CRITICAL,
QOF_LOG_WARNING = G_LOG_LEVEL_WARNING,
QOF_LOG_MESSAGE = G_LOG_LEVEL_MESSAGE,
QOF_LOG_INFO = G_LOG_LEVEL_INFO,
QOF_LOG_DEBUG = G_LOG_LEVEL_DEBUG,
}QofLogLevel;
I can remove the comma from the ENUM_BODY and instead put it in the
LOG_LEVEL_LIST define like this:
#define ENUM_BODY(name, value) \
name value
#define LOG_LEVEL_LIST(_) \
_(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR), \
_(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL), \
_(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING), \
_(QOF_LOG_MESSAGE, = G_LOG_LEVEL_MESSAGE), \
_(QOF_LOG_INFO, = G_LOG_LEVEL_INFO), \
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)
This change prevents the make warning/error, but after making this
change Eclipse then reports a syntax error at the DEFINE_ENUM
(QofLogLevel, LOG_LEVEL_LIST) line (qoflog.h, line 102), and will no
longer explore the macro expansion. I'm not sure then if this is
actually a syntax error (since the compiler does not throw any errors
or warnings) or a bug in Eclipse, but having a macro for such a simple
enum is a bit of a headache.
These macros are used throughout gnucash in a few different places so
I am wary of simply tossing out the DEFINE_ENUM and related macros
completely and replacing them with explicit typedefs since the macros
seem to have at least some usefulness to them, so it seems like a less
invasive fix is needed. I am not sure what the best solution is other
than the one above which causes the Eclipse error. At the moment I
don't have any better ideas and it is quite late so I must return to
this later. There are other similar macros in libqof which seem to
share this structure so I expect to see errors from the other macros
as well at some point. Any suggestions?
Thanks,
-Tim
More information about the gnucash-devel
mailing list