svn commit: samba r10184 - in branches/SAMBA_4_0/source/librpc/rpc: .

derrell at derrell at
Mon Sep 12 22:08:29 GMT 2005

tpot at writes:

> Author: tpot
> Date: 2005-09-12 21:37:18 +0000 (Mon, 12 Sep 2005)
> New Revision: 10184
> WebSVN:
> Log:
> Fix a stack of unhandled enumeration warnings.

> +		break;
> +
> +		/* Fall through to next switch statement */
> +
> +	default:
> +		break;
>  	}

One of the really nice features of using enums is that the compiler can help
the developer find missing code.  When cases aren't handled in a switch
statement, you get this warning.  That luxury is lost if you add a "default:"
label to the switch.

In lieu of adding a "default:" label, instead add a "case" for each of the
specific enum values in the type.  That way, if additional values are added to
the enum at some later date, the developer will get the warning in each switch
statement that references that type, and he can decide whether there is
something specific which must be done in each of those switch statements or
whether he should just add the new value to the list of cases which do nothing
in that switch.

Doing this also indicates to the reader that really and truly, we don't want
to do anything in this switch statement in that particular case and we didn't
just forget to add a case for it.

It makes the code a little longer since you're listing each enum value, but I
believe that the benefits of readability and taking advantage of the compiler
far outweigh that.



More information about the samba-technical mailing list