c - include errno if not accessed directly -


do need include errno.h if don't access errno directly? eg.

void *mem = malloc(16384); if (mem == null) {     perror("malloc");     exit(exit_failure); } 

i tried simple piece of code without including errno.h , worked, i'm not sure if it's ok this. maybe errho.h included in other libraries stdlib.h , don't need explicitly include myself?

you don't need <errno.h> if use perror().

from linux programmer's manual:

name        perror - print system error message  synopsis        #include <stdio.h>         void perror(const char *s);         #include <errno.h>         const char *sys_errlist[];        int sys_nerr;        int errno; 

this means need <errno.h> if use sys_errlist, sys_nerr or errno. note sys_errlist , sys_nerr bsd extensions.

similar entries can found on c99 standard.

7.19.10.4 perror function

synopsis

#include <stdio.h> void perror(const char *s); 

and need <errno.h> if use following:

7.5 errors

1 header <errno.h> defines several macros, relating reporting of error conditions.

2 macros are

edom eilseq erange 

which expand integer constant expressions type int, distinct positive values, , suitable use in #if preprocessing directives; and

errno 

which expands modifiable lvalue 175) has type int, value of set positive error number several library functions.

[...]

4 additional macro definitions, beginning e , digit or e , uppercase letter, 177) may specified implementation.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -