You are a stupid programmer, you can't have that
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Aug 9 18:30:56 UTC 2021
On Mon, Aug 09, 2021 at 06:23:42PM +0000, Daniel N via Digitalmars-d wrote:
> On Monday, 9 August 2021 at 18:00:23 UTC, H. S. Teoh wrote:
> > if (someCondition)
> > doSomething();
> > else
> > doSomethingElse();
> > return 1; // <--- bugfix
> > finishUp();
> >
> > Had braces been required, the `return 1;` would have been introduced
> > in the proper scope and there would have been no problem. But now
> > this fix has introduced a new bug.
[...]
> The above code will fail to compile in recent C/C++ compilers, because
> of suspected intentional backdoors hiding in plain sight using this
> technique.
>
> <source>:7:5: warning: this 'else' clause does not guard...
> [-Wmisleading-indentation]
> <source>:9:9: note: ...this statement, but the latter is misleadingly
> indented as if it were
>
> Thus there's no longer a good reason to avoid this style, unless you
> are using a compiler where this is not yet implemented.
I would not trust a coding style that depends on the compiler to warn
about mistakes. What if the compiler fails to issue the warning in some
obscure corner cases? It's completely preventable: just don't write
code this way.
Besides, it's kinda sad that C is moving towards Python-style
indentation sensitivity...
T
--
This is a tpyo.
More information about the Digitalmars-d
mailing list