I have a global macro that provides logging facilities #define LOG_LOG(name,level,msg,...) { I use the logging facility via another macro LENTER that indirectly invokes/depends on LOG_LOG (definitions below). The macros look like this (defined in logger.h):
#define LOG_LOG(name,level,msg,...) { \
#if defined(OS_MACOSX)\
int tid=mach_thread_self();\
#elif defined(OS_LINUX)\
int tid=syscall(__NR_gettid);\
#elif defined(OS_FREEBSD)\
int tid=reinterpret_cast<int64>(pthread_self());\
#endif\
if (level<=LOGLEVEL_WARNING){\
fprintf(stderr,"%s %i %s:%s():%i",name, tid, __FILE__,__FUNCTION__,__LINE__);\
fprintf(stderr," " LOG_ADDITIONAL);\
fprintf(stderr,"--> " msg, ##__VA_ARGS__);\
fprintf(stderr,"\n");\
}else{\
printf("%s %i %s:%s():%i",name, tid, __FILE__,__FUNCTION__,__LINE__);\
printf(" " LOG_ADDITIONAL);\
printf("--> " msg, ##__VA_ARGS__);\
printf("\n");\
}\
}
#if LOGLEVEL>=LOGLEVEL_TRACE
#define LTRACE(msg,...) LOG_LOG("Trace",5,msg,##__VA_ARGS__)
#else
#define LTRACE(msg, ...) {}
#endif
#define LENTER LTRACE("entering method")
The client code of these macros looks like this:
template<typename T>
inline void tvector<T>::random() {
LENTER;
for (int i = 0; i < size(); ++i) {
elem(i) = (double) rand() / (double) RAND_MAX;
}
}
But I still get the error:
/Users/bravegag/code/fastcode_project/code/src/vector.h: In member function 'void tvector<T>::random()':
/Users/bravegag/code/fastcode_project/code/src/vector.h:223:2: error: there are no arguments to 'LOG_LOG' that depend on a template parameter, so a declaration of 'LOG_LOG' must be available [-fpermissive]
Which I don’t get, since this is a macro available and well defined globally and has absolutely nothing to do with the template parameter of the class of the client member function tvector<T>::random(). Researching about this issue I found the link http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html but this is confusing and far from the issue I have at hand.
This error is telling me that the definition of the LOG_LOG is not available … but it is. I really don’t see how this “two stage name lookup” improves the quality of the code other than creating extremely obfuscated compiler errors.
/Users/bravegag/code/fastcode_project/build_debug$ g++ --version
g++ (MacPorts gcc46 4.6.3_2) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/Users/bravegag/code/fastcode_project/build_debug$ uname -a
Darwin Macintosh-4.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64
You should rewrite your macros to something on the lines of:
Note that if at least in one of your options the thread id is going to be a 64bit integer, you should use 64bit integers all along (else you will not show the correct value for BSD. Remember to pass the appropriate type to
printfor make the thread number logging platform dependent. Also, all three platforms support POSIX, as far as I know, so you might want to provide an uniform implementation that will be easier to maintain.