Sujet : Re: how to make a macro work as a single line if stmt without braces
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 24. Sep 2024, 17:35:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcupof$38rb3$2@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 24/09/2024 15:36, Tim Rentsch wrote:
Michael S <already5chosen@yahoo.com> writes:
The idea of changing the language to always require braces is
unnecessary and wasteful (besides being a non-starter for purely
practical reasons).
Well, practically it is not difficult.
I started modifying my compiler to do it, but found I already had that option, which was a hard-coded value in the source. It took a minute to reenable it. Support for it requires 2-3 lines of code.
However, that makes an exception for if-else chains, so that you can still write:
if (c1) {} else if (c2) {} else if (c3) {}
instead of needing:
if (c1) {} else {if (c2) {} else {if (c3) {}}}
(Maybe the language needs a construct like 'elif', as is used in languages like, say, C's own preprocessor! HTH did that end up with the sensible syntax while the main language was stuck with the rubbish one?)
BTW with mandatory braces enforced, my generated-C applications still build with no problems. Because generated code always uses braces. There is no point in leaving them out, other than perhaps ending up with 0.5% smaller output.