Zack's Kernel News
Zack's Kernel News

Chronicler Zack Brown reports on the latest news, views, dilemmas, and developments within the Linux kernel community.
Bogus GCC Warnings Reveal Real Kernel Problem
Linus Torvalds recently took great pains to explain why even though a particular GCC warning resulted in identifying a true problem with the kernel code, the warning itself was nevertheless bogus and insane. In fact, he said, most of the warnings introduced in GCC 5.1 didn't seem so valuable to him.
The one that had caught his attention, though, was a warning against using a switch
statement with a Boolean variable. Presumably, the GCC folks thought that the whole point of switch
was to operate on several possible values using a simple coding structure, and thus avoid long if
/else
/if
chains. They may have thought that for a Boolean variable, a simple if
statement would be the only appropriate way to go.
In the case of this particular bit of kernel code, said Linus, the warning was good because the switch
statement in the kernel used a Boolean variable, whereas the case
statements did not. He felt that this would be a perfectly legitimate thing for GCC to issue warnings about. But, if the switch
and case
statements both used a Boolean variable, he said, it would be a perfectly fine use case, and might even be better than the equivalent if
/else
in some cases:
[...]
Buy this article as PDF
(incl. VAT)