我有以下代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("Checking\n");
exit(0);
}
在源代码之前,我有两个函数,一个是 printf() ,即
存在于 stdio.h 头文件中。第二个是 exit() 函数,即
存在于 stdlib.h 头文件中。
现在我想要这个程序的输出是:
printf() 函数存在于 stdio.h 中
exit() 函数存在于 stdlib.h 中
有什么办法可以查到这一点吗?
由于标题文本,确实没有可移植的方法来执行此操作甚至根本不需要存在于文件中!按照标准来说还是可以接受的#include <system header file>
简单地修改环境而不参考特定的actual头文件,因此在这种情况下,您无法轻松地从程序访问信息。
就查明标题文本是否is可用,这可能是简单的文本搜索(可能会有误报,因为可能有关于printf
in the math.h
头文件)到一个完整的 C 感知解析器(可能很复杂)。
或者,您可以(手动)参考实际标准,因为这些详细信息在那里可用,例如:
7.21.4.1 The remove function
Synopsis
#include <stdio.h>
int remove(const char *filename);
C11 中的这个小片段意味着remove
函数可以在stdio.h
.
而且,如果你still想要一种在程序中执行此操作的方法,只需将标准中的所有知识收集到文件或数据结构(如关联数组)中,然后编写代码来查找给定的标识符,如下所示:
#include <string.h>
#include <assert.h>
const char *lookFor (const char *ident) {
// These should have ALL identifiers and their
// equivalent headers.
static const char const *identifier[] = { "remove", "strcpy", ... };
static const char const *header[] = { "stdio.h", "string.h", ... };
assert (sizeof(identifier) == sizeof(header));
for (size_t i = 0; i < sizeof(header) / sizeof(*header); i++)
if (strcmp (ident, identifier[i]) == 0)
return header[i];
return NULL;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)