Error: using undeclared identifier 'errno_t'

Here is my dead simple dummy code:

#include <errno.h> int main(void) { errno_t e; return 0; } 

What surprisingly causes this error:

 main.c:5:5: error: use of undeclared identifier 'errno_t' errno_t x; ^ 

I began to follow the tracks: when the compiler sees inclusions <...> , it will first look at /usr/include , where, of course, it found the errno.h file. In fact, there is one line in it, in addition to the comment on the license:

 #include <sys/errno.h> 

Now, with /usr/include/sys in errno.h , I found the following lines:

 #include <sys/cdefs.h> #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 #include <sys/_types/_errno_t.h> #endif 

And in /usr/include/_types in _errno_t.h I found this:

 typedef int errno_t; 

So it looks like it is, and it is an alias of the integer type and part of errno.h - as it should be.

Then why is it not turned on? Why does the compiler raise an undeclared identifier error?

Thanks in advance!


RELATED INFORMATION:

 Compiler: Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)` Compiler flags: -std=c11 -I/usr/include/sys -I/usr/local/include 

The macro variable __STDC_WANT_LIB_EXT1__ will be defined in /usr/include/sys in cdefs.h in the following lines:

 /* If the developer has neither requested a strict language mode nor a version * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part * of __DARWIN_C_FULL. */ #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL #define __STDC_WANT_LIB_EXT1__ 1 #endif 

UPDATE:

As @PaulR said in the comments section: if I -std=c11 , it compiles. This is just as surprising as the error associated with enabling the flag. Therefore, I am spreading this question to the question:

Is errno_t part of the C11 standard, or why is it not included when the standard is specified for the compiler?

+7
c compiler-construction include clang errno
source share
1 answer

errno_t not a standard type; this is part of the optional (and widely disliked and unsupported) K application included in ISO C11, only because of one particular vendor with a history of ignoring and sabotaging the standard.

Since application K defines errno_t as int , the object type is errno int , and all error codes are int , just use int in your programs. This is much more portable than relying on an additional feature that is unlikely to be supported.

+20
source share

All Articles