0

hi i am developing new logger for android. in vc version i used log like this,


//ref http://stackoverflow.com/questions/8487986/file-macro-shows-full-path
  #define CURRENT_FILE_NAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)

//ref ##VAR things - http://www.delorie.com/gnu/docs/gcc/gcc_44.html
//ref define "" __vars__ something - http://mail-archives.apache.org/mod_mbox/httpd-dev/199710.mbox/%3CPine.LNX.3.95.971028083446.14671A-100000@gaia.vr.net%3E
  #define printfAdv(fmt,...)\
    {\
printf("[%s] " fmt " ... @(%s)[%s:%d]\n",__TIME__,##__VA_ARGS__,__FUNCTION__,CURRENT_FILE_NAME,__LINE__);\
fflush(stdout);\
    }
 #define  LOGV(fmt,...)  \
    {\
printfAdv(fmt,__VA_ARGS__);\
    }

->[09:59:42] inputting ... @(processInputKey)[vc_input.cpp:63] and it worked like charm.

but in android, it cannot be built since some error.


 #define  InternalLoggerv(...)  __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)

//ref http://stackoverflow.com/questions/8487986/file-macro-shows-full-path
//win for two back slash
#define CURRENT_FILE_NAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)

//ref ##VAR things - http://www.delorie.com/gnu/docs/gcc/gcc_44.html
//ref define "" __vars__ something - http://mail-archives.apache.org/mod_mbox/httpd-dev/199710.mbox/%3CPine.LNX.3.95.971028083446.14671A-100000@gaia.vr.net%3E
#define printfAdv(fmt,...)\
    {\
InternalLoggerv("" fmt " ... @(%s)[%s:%d]\n",##__VA_ARGS__,__FUNCTION__,CURRENT_FILE_NAME,__LINE__);\
    }

//  fflush(stdout);\
//printf(fmt " ... @(%s)[%s:%d]\n",##__VA_ARGS__,__FUNCTION__,CURRENT_FILE_NAME,__LINE__);\
//printf("[%s] " fmt " ... @(%s)[%s:%d]\n",__TIME__,##__VA_ARGS__,__FUNCTION__,CURRENT_FILE_NAME,__LINE__);\

#define  LOGV(fmt,...)  \
    {\
printfAdv(fmt,__VA_ARGS__);\
    }

This gives error when LOGV("blah blah"); not when LOGV("%s","blah balhh"); and error says 'expected primary-expression before ',' token'....

what makes this differnt, and how can i use sometihng like in android native deveolopemnt? thatnk you.

minimanimo
  • 185
  • 3
  • 11
  • Have a look at the preprocessed source code. – PlasmaHH Apr 23 '13 at 09:18
  • @PlasmaHH what do you mean.. 'preprocessed source code'? – minimanimo Apr 23 '13 at 09:36
  • printf means " _Check_return_opt_ _CRTIMP int __cdecl printf(_In_z_ _Printf_format_string_ const char * _Format, ...); " ... and __android_log_print says " int __android_log_print(int prio, const char *tag, const char *fmt, ...) #if defined(__GNUC__) __attribute__ ((format(printf, 3, 4))) #endif ; " – minimanimo Apr 23 '13 at 09:38
  • Please [see this question](http://stackoverflow.com/questions/7059549/c-multi-line-comments-using-backslash). I think that is your problem. – Jesse Good Apr 23 '13 at 10:06
  • @JesseGood good link but not my case... – minimanimo Apr 23 '13 at 11:49
  • Ohhh solved. not calling intermediate function did it. #define InternalLoggerv(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__) #define LOGV(fmt,...) \ {\ InternalLoggerv("" fmt " ... @(%s)[%s:%d]\n",##__VA_ARGS__,__FUNCTION__,CURRENT_FILE_NAME,__LINE__);\ } – minimanimo Apr 23 '13 at 11:53

0 Answers0