I have a combination of libraries that are suffering from namespace pollution due to the use of macros and macro names in function prototypes of the same name. Specifically, I am using my GUI library Eagle and my friend's networking library Nilorea.
How do I obtain a list of all the function like macros included in my code? I looked at MSVS and CodeBlocks and I can't seem to find a way to list them. I can also use
grep
, but that is only effective on a directory or easily obtained list of files.I read about this (Macro and function with same name) and discovered I can (surround) a function name in a declaration to prevent macro expansion, but that only solves the instances where I am using a function with the same name as the macro. MinGW is using macro names for functions I cannot change.
I avoided some namespace collision by separating out bad headers like
windows.h
and defining NOGDI to avoid some others, but I can't seem to get rid of them all.I know I can
#undef
a symbol if I need to and I've had limited success with this, along with changing the order of inclusion of headers, but I'm still having problems.
So what options do I have to scrub my code of these obnoxious macros?'
I looked at the CPP (C preprocessor) program's help and it doesn't show any abilities to list the macros in a given header.
Do I need to write my own custom solution? What about Clang?
For an example of the collision between Nilorea and MinGW-W64 see here :
This is a macro in Nilorea that collides with mingw :
/*! Free Handler to get errors */
#define Free( ptr ) \
if ( ptr )\
{\
free( ptr );\
ptr = NULL;\
}\
else\
{\
n_log( LOG_DEBUG , "Free( %s ) already done or NULL at line %d of %s \n", #ptr , __LINE__ , __FILE__ );\
}
The compiler error it generates is misleading, but points to c:\mingw\i686-w64-mingw32\include\objidbase.h and oaidl.h in these function prototypes :
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("00000002-0000-0000-c000-000000000046")
IMalloc : public IUnknown
{
virtual void * STDMETHODCALLTYPE Alloc(
SIZE_T cb) = 0;
virtual void * STDMETHODCALLTYPE Realloc(
void *pv,
SIZE_T cb) = 0;
virtual void STDMETHODCALLTYPE Free(
void *pv) = 0;
virtual SIZE_T STDMETHODCALLTYPE GetSize(
void *pv) = 0;
virtual int STDMETHODCALLTYPE DidAlloc(
void *pv) = 0;
virtual void STDMETHODCALLTYPE HeapMinimize(
) = 0;
};