httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Hyde <>
Subject Re: [APR] Universal return syntax
Date Tue, 26 Jan 1999 17:04:43 GMT
Errno style error handling has a number of pit falls that
require coding conventions to avoid.  It would be bad,
dangerous to pretend these don't exist.

As if you could write:

    (result, error_code) = function(a,b,c)
    if( error_code != NO_ERROR ){
     ...manage trouble...

In the standard C technique a purest might write:

    if ( EXCEPTIONAL_VALUE == (result = function(a,b,c))){
      int error_code = errno;
      report_trouble(... error_code ...);
      errno = error_code;

Getting the errno value back on the stack ASAP.

People tend to skip this.  So you get bugs by doing:

    if ( EXCEPTIONAL_VALUE == (result = function(a,b,c))){
      report_trouble(... errno ...);

Which is just wrong pure and simple.  Once you get
this pattern down then you know to fire up your paranoia
every time you see the
    if ( EXCEPTIONAL_VALUE == (result = function(a,b,c))){

in the code.  You have to grab the errno ASAP since it's
very volatile.  It REALLY is a second return value.

The alternate coding style that looks like:
     error_code = f(&result, ...);
reduces the chance of this error, yes.  It is a coding
convention for safety, just like the one above.  It's
problem is it's neither traditional nor fast.

 - ben

View raw message