3 ms·
You didn't say it explicitly, but your original comment came off more like "This option is unnecessary and should be removed from gcc, since we can simply enfor
by MichaelBurge 11y ago
You didn't say it explicitly, but your original comment came off more like "This option is unnecessary and should be removed from gcc, since we can simply enforce a style of using curly braces everywhere"
C doesn't do this, but I like this feature from Perl for single-statement checks:
return if is_red($traffic_light);
return unless is_green($traffic_light);
In C, I usually put the early returns on their own line without curly braces, but place them all together at the start of the function to make it easier to spot inconsistencies.
- kbenson 11y agoI love that feature of Perl, and to be explicitly clear to those that are unfamiliar with it, Perl does not allow unbraced single line if's in the normal sense (pre-conditional ifs), and does not allow braced post-conditional ifs. For example, these are valid: if ( $foo ) { bar(); baa(); } quux() if $foo; And these are not: if ( $foo ) bar(); { bar(); baz(); } if $foo;