C++ Logo

liaison

Advanced search

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

From: Jₑₙₛ Gustedt <jens.gustedt_at_[hidden]>
Date: Fri, 6 Oct 2023 14:35:30 +0200
Ville,

on Fri, 6 Oct 2023 14:24:07 +0300 you (Ville Voutilainen
<ville.voutilainen_at_[hidden]>) wrote:

> On Fri, 6 Oct 2023 at 12:24, Jens Gustedt <jens.gustedt_at_[hidden]>
> wrote:
> > > It wasn't obvious to me whether the concern is about the
> > > feasibility of using such words or a usability matter.
> > > "pre" and "post" would indeed be highly problematic to try to make
> > > actual full keywords, which is why they're not.
> >
> > ok
> >
> > for C we woudn't know how to make such subtle differences for words
> > with fixed meaning in the grammar. So if we would do that, this
> > would be either keywords or predefined macros (that come from a
> > header, usually)
>
> Well, it's rather important that words such as "pre" and "post" aren't
> reserved elsewhere other than at a particular location in function
> declarations. It also doesn't seem
> feasible to provide such words as any sort of identifiers declared in
> a standard library header, because the intent is to allow using them
> as function names or variable names. 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++.

As said, in C we currently don't have the possibility to do such
subtle differences in placement of "words" after preprocessing. This
would be completely novel for C, and so it has only limited chances to
be adopted.

The only tools that we have in C to avoid clashes with user
identifiers are those that were mentionned up-thread, that is use
reserved names with some kind of prefix, and have a syntax that is
macrosiable. So if C++ wants such extensions to enter in C at some
point, or even if you want to maintain header compatibility, I'd
strongly advise to take this into account.

> Our field experience, limited in scope and audience as it may be,
> suggests that there's no particular comprehension problem for users of
> this facility.

I can imagine that, but I can also imagine that if that feature is
more largely used and distributed that it will cause some irritation
with far-away users that are completely at the receiving end of
this. I guess that people that use C++ headers already have some sort
of tolerance for new concepts and weird syntax. This might be
different for users coming from whatever language and who have to read
C interfaces that they inherit in some project.

I still remember when I presented the C11 thread interfaces with their
`thrd_` prefix to users not in the center of the C or C++ communty,
how they made fun of us for this abreviationitis.

And as said, for me the gain in typing some characters more or less is
not very relevant when I am coding. First, there are IDEs to ease the
tasks, and then typing is not really the bottleneck when I develop
code ;-)


Thanks
Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2023-10-06 12:35:34