开发者

Header included but declarations still missing?

Here's a simple example:

#include <stdlib.h>

int main(void) {
    _set_error_mode(_OUT_TO_STDERR);
    return EXIT_SUCCESS;
}

When compiling this program, I get the following problems:

main.c: In function 'main':
main.c:4: error: implicit declaration of function '_set_error_mode'
main.c:4: error: '_OUT_TO_STDERR' undeclared (first use in this function)
main.c:4: error: (Each undeclared identifier is reported only once
main.c:4: error: for each function it appears in.)

The header does contain the function declaration and the macro:

_CRTIMP int __cdecl __MINGW_NOTHROW _set_error_mode (int);
# define _OUT_TO_STDERR 1

How come I get the errors? Notice that I also used the EXIT_SUCCESS macro which is also defi开发者_运维技巧ned in the same stdlib.h header but for some reason GCC doesn't complain about it. Odd.

I'm using MinGW + GCC on a Vista machine.


Your code snippet works fine for me with MinGW 3.4.5

Are you sure you have your include file path set correctly? Maybe the wrong stdlib.h is being processed. Alternatively, maybe MingGW isn't defining __MSVCRT__ which is necessary to get that function prototype (MinGW seems to define that automatically for me - I'm not sure how one would turn it off).


edit:

tyranid's comment seems to have the answer - if I specify the -ansi option, I get the exact same set of errors as in your example.

Setting to CW and will delete if tyranid posts an answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜