C++ Logo


Advanced search

Re: [wg14/wg21 liaison] P2961R1 syntax for Contracts: viable for C?

From: Niall Douglas <s_sourceforge_at_[hidden]>
Date: Thu, 05 Oct 2023 16:04:07 +0000
On 05/10/2023 16:09, Aaron Ballman via Liaison wrote:

> The syntax that looks like `pre (i >= 0)` is slightly problematic in C
> in that it's using an unreserved identifier. However, I think that's
> pretty easy to work around by introducing it as `_Pre` in C and
> providing something like a `<stdcontracts.h>` with a macro so you can
> get the `pre` spelling in header code shared between C and C++.
Surely these can be made context sensitive keywords, so if somebody uses
`pre` or `post` anywhere else, that's fine? If so, do we really need
_Pre and _Post?

That would leave the people who define preprocessor macros `pre` and
`post`, but whether on C++ or C++ that would have the same outcomes.

Also, for the record, I agree with Aaron that contracts are probably
even more useful for C than for C++. There is a whole bunch of C which
would benefit greatly from them.

I also concur that I prefer this syntax to an attributes based one.


Received on 2023-10-05 16:04:09