gpt4 book ai didi

c - vfprintf 导致运行时错误

转载 作者:可可西里 更新时间:2023-11-01 11:40:42 26 4
gpt4 key购买 nike

Visual Studio 2008

我正在使用以下源代码,使用 linux gcc 4.4.1 编译正常。

但是,我正在尝试使用 VS 2008 编译为 c 代码在 windows xp sp3 上进行编译。

我在调用 vfprintf 时遇到运行时错误。而且 __func__ 给我一个编译错误。 “未声明的标识符”。我认为 __func__ 是在 stdarg.h 文件中定义的。

非常感谢任何建议,

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

void log_msg(FILE *out, const char *fmt, ...);

int main(void)
{
printf("== Start program ===\n");

log_msg(stderr, "[ %s ] : [ %s ] : [ %d ]\n", __FILE__, __func__, __LINE__);

return 0;
}

void log_msg(FILE *out, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(out, fmt, ap); /* run-time error here */
va_end(ap);
}

最佳答案

__func__ 是 C99 结构,在 Visual Studio 中不可用。您可以尝试改用 __FUNCTION__

除此之外,您的示例对我来说效果很好。

关于c - vfprintf 导致运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1705324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com