造冰箱的大熊貓@cnblogs 2024/6/20
1、可變參量
#include <stdio.h> #include <stdarg.h> void debugprint ( const char *format, ... ) { va_list args; va_start(args, format); printf(format, args); va_end(args); } int main()
{ debugprint ( "Hello, %s!\n", "world" ); debugprint ( "The value is: %d, %d, %d\n", 10, 20, 30 ); return 0; }
2、debugprint函式
#include <stdio.h> #include <stdarg.h> void DebugPrintFunc ( const char *format, ... ) { va_list args; va_start(args, format); printf(format, args); va_end(args); } #ifdef _DEBUG #define debugprint (format, args...) DebugPrintFunc(format, args) #else #define debugprint (format, args...) #endif
int main()
{
debugprint ( "Hello, %s!\n", "world" );
debugprint ( "The value is: %d, %d, %d\n", 10, 20, 30 );
return 0;
}