ISO C委员会(ISO/IEC JTC1/SC21/WG14)已发布TR 24731-1,正在研究TR 24731-2:
TR 24731-1:C库的扩展第一部分:边界检查接口
WG14正在研究更安全的C库函数.该TR旨在通过添加具有缓冲区长度的额外参数来修改现有程序.最新草案见N1225号文件.理由是在N1173号文件中.这将成为技术报告类型2.
TR 24731-2:C库的扩展 - 第二部分:动态分配功能
WG14正在研究更安全的C库函数.该TR面向使用动态分配而不是缓冲区长度的额外参数的新程序.最新草案见N1337号文件.这将成为技术报告类型2.
找到此代码,需要停止将戴尔笔记本电脑中的 CPU 节流至 20%,这是由于电源适配器无法被计算机识别而发生的。
\n\n尝试在 Kubuntu 上编译并得到以下结果:
\n\nwarning: implicit declaration of function \xe2\x80\x98asprintf\xe2\x80\x99; did you mean \xe2\x80\x98vasprintf\xe2\x80\x99? [-Wimplicit-function-declaration]\n 47 | if (asprintf(&concat_cmd, "%s %i", cmd, *reg_value) == -1)\n | ^~~~~~~~\n | vasprintf\nRun Code Online (Sandbox Code Playgroud)\n\n我不明白为什么会发生这种情况。我读到这是libiberty-devasprintf的一部分。库已安装,但一切都不起作用。我还添加了
#include <libiberty/libiberty.h>\nRun Code Online (Sandbox Code Playgroud)\n\n并得到相同的 - 函数 \xe2\x80\x98asprintf\xe2\x80\x99 的隐式声明
\n\n告诉我该怎么办?
\n\n#include <string.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <libiberty/libiberty.h>\n\n#define BUFSIZE (64)\n\nint get_msr_value(uint64_t *reg_value) {\n const char *cmd = "rdmsr -u 0x1FC";\n char cmd_buf[BUFSIZE];\n\n FILE *fp;\n\n if ((fp = popen(cmd, "r")) == NULL) …Run Code Online (Sandbox Code Playgroud) 我有一个返回整数值的函数.现在我想编写一个调用此函数的宏,获取返回值并在其前面添加一个字符串并返回结果字符串.
我试过这个:
#define TEST(x) is_enabled(x)
Run Code Online (Sandbox Code Playgroud)
我在main函数中将此宏称为:
int ret = 0;
ret = TEST(2);
printf("PORT-%d\n", ret);
Run Code Online (Sandbox Code Playgroud)
这非常有效.但是我希望宏返回字符串PORT-x,其中,x是被调用函数的返回值.我怎样才能做到这一点?
编辑:
我也尝试将它写成多行:
#define TEST(x)\
{\
is_enabled(x);\
}
Run Code Online (Sandbox Code Playgroud)
并在主函数中将其称为:
printf("PORT-%d\n", TEST(2));
Run Code Online (Sandbox Code Playgroud)
但这会产生编译时错误:
error: expected expression before â{â token
Run Code Online (Sandbox Code Playgroud)