我想open_memstream在我的C代码中使用该函数.但是我似乎无法编译它.最小的工作示例如下:
#include <stdio.h>
int main(void) {
char *buf;
size_t sz;
FILE *stream = open_memstream(&buf, &sz);
putc('A', stream);
fclose(stream);
}
Run Code Online (Sandbox Code Playgroud)
我还使用以下命令编译它:
gcc -std=c99 -o test test.c
经过一些研究,我发现在包含之前我需要定义一个宏stdio.h.但是,以下示例代码无济于事.
#define __USE_POSIX
#define __USE_XOPEN
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)
抛出以下编译器警告; 我假设第二个警告是因为第一个警告.
test.c:7:17: warning: implicit declaration of function ‘open_memstream’ [-Wimplicit-function-declaration]
FILE *stream = open_memstream(&buf, &sz);
^
test.c:7:17: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
Run Code Online (Sandbox Code Playgroud)