6

I use a LOG_DEBUG function to print debug information to the screen. I used a #define _DEBUG to disable LOG_DEBUG function by defining _DEBUG FLAG in compile time (release time). but linux strings commands of release build app still shows debug strings which exists in the compiled app. so what is the alternatives to eliminate arguments of LOG_DEBUG?

#ifdef _DEBUG
#define LOG_DEBUG(fmt, ...) printf("[D][%s:%d %s]", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
#endif


LOG_DEBUG("this is a debug string");     // "this is a debug string" exists in app release build yet

the compiler I use: ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 569]

optimization: -O3

4

1 回答 1

3

您可以尝试使用stringification

#include <stdio.h>

#define _DEBUG

#ifdef _DEBUG
#define LOG_DEBUG(str) do { printf("[D][%s:%d %s] ", \
                               __FILE__, \
                               __LINE__, \
                               __FUNCTION__); \
                            puts(#str); } while(0)
#else
#define LOG_DEBUG(str)
#endif

int main() {
  LOG_DEBUG(this is a debug string);
  return 0;
}

注意:我在 clang 中对此进行了测试,它没有表现出您描述的行为。

于 2017-06-01T21:47:05.147 回答