Casting an expression to bool means testing for 0 or !=0 for	arithmetic types
    Dmitry Olshansky 
    dmitry.olsh at gmail.com
       
    Sat Jul 31 15:00:45 PDT 2010
    
    
  
On 31.07.2010 23:44, Pluto wrote:
> This part has always bothered me. Could somebody please explain to me the
> rationale behind limiting functions to one usable error code?
>
> if(function())
> ~~
>    
Inherently if is for testing _condition_ which is true/false. Going 
futher you'd just reinvent switch statement.
which if perfectly OK for it, here it goes:
     switch(function()){
         case ERR_CODE1:
             // ---
         break;
         case ERR_CODE2:
             // ---
         break;
             // ---
         default:
             // ---
         break;
     }
Honestly, I'd suggest using exceptions instead of error codes.
Usage of error codes scales poorly and itself is very error-prone, also 
killing the return value of functions just for error code leads to very 
awkward design.
> :Pluto
>    
-- 
Dmitry Olshansky
    
    
More information about the Digitalmars-d-learn
mailing list