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 erangewhich expand integer constant expressions type
int, distinct positive values, , suitable use in#ifpreprocessing directives; anderrnowhich expands modifiable lvalue 175) has type
int, value of set positive error number several library functions.[...]
4 additional macro definitions, beginning
e, digit ore, uppercase letter, 177) may specified implementation.
Comments
Post a Comment