Re: [PATCH 1/3] Documentation/CodingGuidelines: explain why assert is bad
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Nov 22, 2017, 23:54 UTC
- Message-ID
- <20171122235425.GK11671@aiede.mtv.corp.google.com>
- In-Reply-To
- <CAGZ79kY7yrgYSM7jLQD3Q4sRpjovXY=HZwU4M-Ai_XRPseda9A@mail.gmail.com>
Stefan Beller wrote:
> On Wed, Nov 22, 2017 at 2:59 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 8 quoted lines
>> In a certain ideal world, the preference would be reversed: you'd want >> to use assert() wherever you can and require the compiler to check >> that all assert()s are verifiable at compile time. A check that a >> static analyzer can verify is more valuable than a run-time check. >> When a compile-time check is not possible, you'd have to fall back to >> BUG_ON(). > > Linux has BUILT_BUG_ON as well, which we may desire?
I thought so until I tried to use it: https://public-inbox.org/git/20170830065631.GH153983@aiede.mtv.corp.google.com/
So I think we are stuck with run-time checking for now.
Thanks, Jonathan