+ 1

Why am I getting this warning when using extern int errno?

All my C programs are always built on Linux like systems, but this time I'm programming on a Windows system. Every time I use the global variable errno from errno.h I get the following warning: #include <stdio.h> #include <errno.h> extern int errno; int main() { errno = -10; printf("%d\n", errno); return 0; } Warning: '_errno' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] extern int errno; Funny, when I comment that line the warning disappear, but why? I really don't understand why that warning is displayed, because when I compile the same code on a linux system, gcc doesn't display nothing. In both cases, I use flags -g and -Wall to debug program..... I will appreciate if someone explain me this, thank youđŸ€—đŸ˜€

6th Mar 2022, 4:52 AM
Hacker-KR4636
Hacker-KR4636 - avatar
5 Respostas
+ 3
Why are you redeclaring 'errno'? Is there any purpose of doing that? I think that is the problem, because the compiler warns that '_errno' (errno is a macro which probably expands to '_errno'...?) is "redeclared". It was probably declared with an attribute in the errno.h header, which you are redeclaring without the attribute.
6th Mar 2022, 5:44 AM
XXX
XXX - avatar
+ 1
No bro, there isn't any purpose of doing it, it's just that sometimes I write that sentence on linux and I don't get any warnings, that's why I am curious, but you're right, maybe that errno version was declared with some attribute, thank you bro. I will remove that line😀
6th Mar 2022, 7:35 AM
Hacker-KR4636
Hacker-KR4636 - avatar
+ 1
Hacker-KR4636 You have to remember that 'errno' is a macro https://en.cppreference.com/w/cpp/error/errno What it expands to is "implementation-defined", which means it expands to different things on different compilers, which might be the reason why you get a warning on one but not on another.
6th Mar 2022, 8:23 AM
XXX
XXX - avatar
0
AzhagesanăƒŸ(˙❄˙) ChillPill đŸŒ¶ XXX Hope you can help me with this problem. Thanks in advanceđŸ€—đŸ˜€
6th Mar 2022, 5:19 AM
Hacker-KR4636
Hacker-KR4636 - avatar
0
Yeah, You're right bro. Thank you so much for helping me brođŸ€—đŸ˜˜đŸ€—đŸ€—đŸ˜€đŸ˜€đŸ™đŸ™đŸ™
6th Mar 2022, 8:28 AM
Hacker-KR4636
Hacker-KR4636 - avatar