I am working on removing warnings from legacy code when I encountered the below macro
#define DISBALE_DEBUG
#ifdef DISBALE_DEBUG
#define Dbg(fmt,...) (0)
#else
#define Dbg print
#endif
and used in the below code:
#ifdef __arm__
Dbg("\n %s %s %d %d \n", __FILE__, __FUNCTION__, __LINE__, mode);
#endif
for which i get the warning: ** expression has no effect**
If you enter the DISBALE_DEBUG
#ifdef
branch, the Dbg
macro will be defined as a variadic macro which just consumes its variadic arguments and does nothing with them. Ie, a call such as
Dbg("\n %s %s %d %d \n", __FILE__, __FUNCTION__, __LINE__, mode);
will resolve to
(0);
which, as the compiler accurately warns you about, has no effect.
If you enter the #else
branch, on the other hand, the Dbg
macro will just be a replacement, by the pre-processor, with print
, meaning
Dbg("\n %s %s %d %d \n", __FILE__, __FUNCTION__, __LINE__, mode);
resolves to
print("\n %s %s %d %d \n", __FILE__, __FUNCTION__, __LINE__, mode);
Now, given the information in your question, it is unclear what print(...)
will resolve to, as it is not a standard function in C++ nor C . It's likely another variadic macro or a variadic function .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.