C++ Logo

liaison

Advanced search

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

From: Timur Doumler <cpp_at_[hidden]>
Date: Fri, 6 Oct 2023 16:02:26 +0300
Hi Ville,

> On 6 Oct 2023, at 14:24, Ville Voutilainen via Liaison <liaison_at_[hidden]> wrote:
> If you mean something like
> _Precondition/_Postcondition as predefined macros, then we're no
> longer talking about using the same syntax for C and C++.

Sorry if I did not make this sufficiently clear. The intention of this thread wasn't to find out whether we can use exactly the same syntax for Contracts in C and C++. The intention of this thread was to find out whether we can have a *compatible* syntax, and specifically whether one of the two candidate syntax would be more compatible than the other, i.e. would make it significantly easier for C to adopt a compatible facility.

My metric for "compatible" is not whether Contracts work exactly the same, or are spelled exactly the same in both C and C++, but whether there is some viable path towards having headers shared between C and C++ using some subset of the C++ Contracts facility that is useful for both languages, and having that work in a sufficiently similar way that it's usable in practice. Would you agree that this is a more useful metric here than "using the same syntax for C and C++"?

If we adopt the P2961 syntax in C++ and C ends up having `_Pre` instead of `pre`, and then doing `#define pre _Pre` in a new header "stdcontracts.h", then for me that counts as *compatible*.

If we adopt the P2935 syntax in C++, but C says that for them, everything inside [[ ... ]] needs to be token-ignorable, then for me that counts as *incompatible* because contracts in C++ are not, and can not be, token-ignorable – unless C decides that for them, token-ignorable contracts are fine and that this would be a difference in behaviour between C and C++ that they can live with.

Does that make sense?

Cheers,
Timur

Received on 2023-10-06 13:02:39