Re: [PATCH 2/3 v2] Handle all enum members in case statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/07/2015 11:47 PM, Christopher Li wrote:


On Tue, Aug 4, 2015 at 7:52 PM, Tony Camuso <tcamuso@xxxxxxxxxx <mailto:tcamuso@xxxxxxxxxx>> wrote:
 >
 > It was mentioned to me that the new prevailing wisdom is to "Prefer
 > compile time errors to runtime errors", such that each enum'd value
 > of a switch variable should be explicitly handled.

Most of the code I saw, when using fail through, has comment emphasizing
the fall through behavior.


 > Or, if you prefer, I can resubmit the original patch with a linefeed after
 > the "default:" for good form. Either way, I believe the compiler optimize
 > them the same.

Yes, I prefer the patch without have to list every enum member just to
skip them.

 > The whole reason for explicitly listing the existing enum members is so
 > that new cases for which "break" may not be the correct solution can be
 > easily identified at compile time.

I can see that. However it only works for the switch statement that does
not have the default handler already. In the field a lot of the switch statements
already have default handler, depending on the compiler to give warning is
not that reliable. Unless we ban the default handler all together.

Chris


Thanks Chris,

I will resubmit the original patch with your recommendation for a newline
after the default: case.

Regards,
Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux