【发布时间】:2014-10-19 11:17:30
【问题描述】:
第 3 方库在标题中包含已定义状态变量的列表
// <status.h> -- 3rd party header file
#define SUCCESS 0
#define FAILURE 1
#define OUT_OF_MEM 2
// ... and a lot of them ...
// Functions that return the above status
int Send();
我想显示状态名称,即那些定义的变量名称
// "main.c"
#include <status.h>
#include <stdio.h>
void printstat(stat)
{ // Print out stat with variable name
// Example if 0, print "SUCCESS", and so on...
}
void main()
{
int stat = Send();
printstat(stat);
}
由于定义状态变量太多,那么有什么简单的方法来做到这一点?
【问题讨论】:
-
通过读取程序中的status.h来创建反向查找表。