关于C#:vfprintf导致运行时错误

vfprintf causes run-time error

Visual Studio 2008年

我正在使用下面的源代码,这些源代码使用linux gcc 4.4.1可以正常编译。

但是,我试图使用VS 2008编译为C代码在Windows XP SP3上进行编译。

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

非常感谢您的任何建议,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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 ===
"
);

    log_msg(stderr,"[ %s ] : [ %s ] : [ %d ]
"
, __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__代替。除此之外,您的示例对我来说还不错。


此外,__func__也未在头文件中定义,它是预定义的常量。 请参见我可以将func替换为C宏中的标识符名称吗? 更多。