A
Albert
Hi, Santos wrote in
http://groups.google.com/group/comp...013a981b1809585b?q=greedy+gift+givers&lnk=nl&:
What do ERANGE, EDOM, EILSEQ represent and how do I 'check errno for
the presence of [these] document error values'?
http://groups.google.com/group/comp...013a981b1809585b?q=greedy+gift+givers&lnk=nl&:
What you do when a function has failed will obviously be highly
dependant on the exact situation, but for small test programs (like
yours) you might want to print a useful message printing what went
wrong and where (function and source line number) and probably, exit.
Recovery strategies (even if they are possible) may be too advanced at
this point.
An example:
if (fscanf(file, "%d", &i) != 1) {
fprintf(stderr, "%s (%d): fscanf() failed.\n",
__FILE__, __LINE__);
exit(EXIT_FAILURE);
> }
With C99 you can also use the predefined identifier __func__ to extract
the name of the current function (as a string).
For checking the internal consistency of the program you can use the
macro assert in assert.h. If the expression passed to assert evaluates
to zero (logically false), assert will print a message and abort the
program. You can define the macro NDEBUG *prior* to including assert.h
to turn off all assertions.
Many library functions also set the object 'errno' to some integer value
upon failure. To use this mechanism you need to include the header
errno.h and set errno to zero before the function in question is
called. Immediately after you need to check errno for the presence of
documented error values (like ERANGE, EDOM, EILSEQ and other
implementation defined values), and if so, take appropriate action. You
can translate the error codes in errno to implementation specific
messages using the strerror or perror.
What do ERANGE, EDOM, EILSEQ represent and how do I 'check errno for
the presence of [these] document error values'?