several useful macros:
//macro.cpp
#include <iostream>
#include <string.h>
using namespace std;
#define DEBUG(x) cout << #x " = " << x << "/n"
#define TRACE(s) cerr << #s "/n", s
#define FIELD(a) char* a##_string; int a##_size
void print(char c)
{
cout << c << "/n";
}
int main()
{
FIELD(one);
one_string = "Hello";
one_size = strlen(aone_string);
DEBUG(aone_string);
for(int i = 0; i < aone_size; i++)
TRACE(print(aone_string[i]))
return 0;
}
//macro.cpp
#include <iostream>
#include <string.h>
using namespace std;
#define DEBUG(x) cout << #x " = " << x << "/n"
#define TRACE(s) cerr << #s "/n", s
#define FIELD(a) char* a##_string; int a##_size
void print(char c)
{
cout << c << "/n";
}
int main()
{
FIELD(one);
one_string = "Hello";
one_size = strlen(aone_string);
DEBUG(aone_string);
for(int i = 0; i < aone_size; i++)
TRACE(print(aone_string[i]))
return 0;
}
本文提供了一个使用C++宏定义进行调试输出及字段声明的示例代码。通过宏定义实现了变量的输出调试功能和字段的简洁声明。该示例展示了如何使用预处理器指令来辅助开发过程。
100

被折叠的 条评论
为什么被折叠?



