我正在制作一个嵌入式Linux项目,我想做一个简单的调试消息库,当我的代码处于生产阶段时,我可以在其中禁用调试消息(使用预编译指令)并替换数据库中某种类型的日志(将来)。我在重新实现时遇到了麻烦,printf()因为va_list. 到目前为止,这是我的代码:
我的源文件:
\n#include "debug_msgs.h"\n\n#define ENABLE_DEBUG_MSGS 1U\n\n#if ENABLE_DEBUG_MSGS\n\nint print(const char *fmt, ...) {\n int n = -1;\n va_list ap;\n va_start(ap, fmt);\n n = printf(fmt, ap);\n va_end(ap);\n return n;\n}\n\n#else\n\nint print(const char *fmt, ...) {\n return 0;\n}\n\n#endif\nRun Code Online (Sandbox Code Playgroud)\n我的头文件:
\n#ifndef DEBUG_MSGS_H\n#define DEBUG_MSGS_H\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <stdint.h>\n#include <unistd.h>\n\nint print(const char *fmt, ...);\n\n#endif\nRun Code Online (Sandbox Code Playgroud)\n我的问题是:\n我的实现可以编译(我知道这并不意味着什么),但是当我做一个简单的测试时,例如:
\nint num1 = 10;\nint num2 = 100;\nint num3 = 1000;\nfloat floating = 3.14;\nchar str[] = {"Please work, please"};\nint number=-1;\nnumber = …Run Code Online (Sandbox Code Playgroud)