On 17/02/17 12:37, Luc Van Oostenryck wrote: > In fact this warning is correct, by design. > Your not supposed to cast a bitwise type, even zero. But you _are_ allowed to initialise a bitwise typed variable with zero... This is inconsistent; if a value is implicitly convertible to a type, it should also be legal to cast it explicitly to that type. Such is the case with all types in standard C. So it's my opinion that the design is wrong. > Here is a few examples that doesn't give a warning: > mask[1] = 0; > mask[2] = ~msk; > mask[3] = ~(__force __be32) 0; > mask[4] = ~({ __be32 msk = 0; msk; }); > > The canonical way to do what you need is via the (__force ...) cast. > In fact, in the driver you're talking about, just a few lines above > this fill_mask() function, there is a few masks already defined that > do exactly this, like IP4_ADDR_FULL_MASK. Yes, and I'd actually like to be able to remove __force from those casts as well; __forced casts are a very big hammer that imho should be confined to things like architecture-specific code. They should not be needed in drivers; they certainly should not be needed for a conversion that can occur implicitly. You mention that ({ __be32 msk = 0; msk; }) works. But surely that is a strictly less forceful cast than (__be32)0, since it is using an implicit conversion, and if that doesn't give a warning, then neither should the explicit cast. So can you explain to me why 0 should be treated specially by _everything except_ the cast operator? -Ed The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited. -- 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