Sujet : Re: The joy of FORTRAN
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : alt.folklore.computers comp.os.linux.miscDate : 01. Oct 2024, 11:24:56
Autres entêtes
Organisation : Stefan Ram
Message-ID : <wrapper-20241001111737@ram.dialup.fu-berlin.de>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Peter Flass <
peter_flass@yahoo.com> wrote or quoted:
The Natural Philosopher <tnp@invalid.invalid> wrote:
printf("hello world"); That's bug proof.
Wait, what? Where’s your error checking? What if your printf fails?
Actually that’s one of the things I like least about C. It leaves all error
checking up to the programmer instead of having even a minimal handler for
errors not otherwise caught.
You could write a wrapper for printf, "myprintf",
that will call printf and then do minimal error handling.
#include <stdio.h>
#include <stdarg.h>
int myprintf( char const * format, ... )
{ va_list args;
va_start( args, format );
int const result = vprintf( format, args );
va_end( args );
if( result < 0 )fprintf
( stderr, "Error: printf failed with return code %d\n", result );
return result; }