Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"Any excuse will serve a tyrant." -- Aesop


devel / comp.std.c / Article by Simon Tatham about Flaw in _Generic

SubjectAuthor
* Article by Simon Tatham about Flaw in _GenericKaz Kylheku
`* Article by Simon Tatham about Flaw in _GenericKaz Kylheku
 `- Article by Simon Tatham about Flaw in _GenericMartin Uecker

1
Article by Simon Tatham about Flaw in _Generic

<20230730135125.994@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=542&group=comp.std.c#542

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.std.c
Subject: Article by Simon Tatham about Flaw in _Generic
Date: Sun, 30 Jul 2023 21:39:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20230730135125.994@kylheku.com>
Injection-Date: Sun, 30 Jul 2023 21:39:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e03ffdfa499b0f433ff65455cb09cf27";
logging-data="3185769"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/onqneen5SibEzES7ph60tJjGZtfUIdRU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:4DXcbN/zll5xkpb5eCX9q12yABs=
 by: Kaz Kylheku - Sun, 30 Jul 2023 21:39 UTC

https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/

In spite of _Generic being a compile-time type switch, the unused
clauses all have to type check with a given argument.

E.g. any of the cases maps an argument x to (x)->memb, then
the argument cannot be a "char *".

_Generic should only require that the clauses parse, using
the minimal amount of type information to that aim,.

(If the clauses don't parse, they cannot be identified,
so the construct cannot work. When sscanning the association
list, when the implementation encounters a nonmatching type,
it has to parse the associatead expression in order to find
the next clause in the association list.)

I would havce designed this with required parentheses:

_Generic(expr, t1: (e1), t2: (e2), ... :default (edfl));

Only the matching expression would be fully parsed; the non-matching
ones would be regarded as token sequences in which parentheses and
braces have to balance.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Article by Simon Tatham about Flaw in _Generic

<20230731103604.125@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=543&group=comp.std.c#543

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.std.c
Subject: Re: Article by Simon Tatham about Flaw in _Generic
Date: Mon, 31 Jul 2023 17:40:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20230731103604.125@kylheku.com>
References: <20230730135125.994@kylheku.com>
Injection-Date: Mon, 31 Jul 2023 17:40:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="db4e7d5525dd2ff2477b6d7afaeaf07f";
logging-data="3512909"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zwV1Ucd0+UFVkJz7SPq7cUx4t2VTBGuU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:wQF7FnEbwzPpRy9eBju9UsC5fwQ=
 by: Kaz Kylheku - Mon, 31 Jul 2023 17:40 UTC

On 2023-07-30, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
> https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/
>
> In spite of _Generic being a compile-time type switch, the unused
> clauses all have to type check with a given argument.
>
> E.g. any of the cases maps an argument x to (x)->memb, then
> the argument cannot be a "char *".
>
> _Generic should only require that the clauses parse, using
> the minimal amount of type information to that aim,.
>
> (If the clauses don't parse, they cannot be identified,
> so the construct cannot work. When sscanning the association
> list, when the implementation encounters a nonmatching type,
> it has to parse the associatead expression in order to find
> the next clause in the association list.)
>
> I would havce designed this with required parentheses:
>
> _Generic(expr, t1: (e1), t2: (e2), ... :default (edfl));
>
> Only the matching expression would be fully parsed; the non-matching
> ones would be regarded as token sequences in which parentheses and
> braces have to balance.

Another idea is to parse and type check each of the en, but inside each
one, pretend that expr has the type of tn.

We invent a generated symbol __g0025 and transform
the construct like this. Here I'm using GCC brace expression
syntax ({ ... }):

_Generic(expr,
t1 : ({t1 __g0025 = expr; ee1; }),
t2 : ({t2 __g0025 = expr; ee2; }),
// ...)

Here ee2 denotes e1, but with __g0025 substituted for
expr (so that expr is evaluated only once).

Under this transformation, the ony type error we have
in the dead clauses occurs in the initialization of
__g0025 which isn't compatible with tn on the left.

The implementation can arrange to suppress that
diagnostic, and then just parse and type-check ee2, which has a
correctly typed __g0025 in scope.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Article by Simon Tatham about Flaw in _Generic

<6baa22a1-6377-4a62-9892-2569d258195an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=544&group=comp.std.c#544

  copy link   Newsgroups: comp.std.c
X-Received: by 2002:a05:6214:14f2:b0:63d:34c4:c0b8 with SMTP id k18-20020a05621414f200b0063d34c4c0b8mr60261qvw.10.1690958139840;
Tue, 01 Aug 2023 23:35:39 -0700 (PDT)
X-Received: by 2002:a05:6808:1894:b0:3a7:2570:dd11 with SMTP id
bi20-20020a056808189400b003a72570dd11mr15087713oib.6.1690958139510; Tue, 01
Aug 2023 23:35:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.std.c
Date: Tue, 1 Aug 2023 23:35:39 -0700 (PDT)
In-Reply-To: <20230731103604.125@kylheku.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a02:8388:e203:9700:99cd:2b19:8a87:7ba2;
posting-account=RQgdUAoAAACC04vq-o2ZyxdALW1NmdRY
NNTP-Posting-Host: 2a02:8388:e203:9700:99cd:2b19:8a87:7ba2
References: <20230730135125.994@kylheku.com> <20230731103604.125@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6baa22a1-6377-4a62-9892-2569d258195an@googlegroups.com>
Subject: Re: Article by Simon Tatham about Flaw in _Generic
From: ma.uecker@gmail.com (Martin Uecker)
Injection-Date: Wed, 02 Aug 2023 06:35:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4168
 by: Martin Uecker - Wed, 2 Aug 2023 06:35 UTC

On Monday, July 31, 2023 at 7:40:29 PM UTC+2, Kaz Kylheku wrote:
> On 2023-07-30, Kaz Kylheku wrote:
> > https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/
> >
> > In spite of _Generic being a compile-time type switch, the unused
> > clauses all have to type check with a given argument.
> >
> > E.g. any of the cases maps an argument x to (x)->memb, then
> > the argument cannot be a "char *".
> >
> > _Generic should only require that the clauses parse, using
> > the minimal amount of type information to that aim,.
> >
> > (If the clauses don't parse, they cannot be identified,
> > so the construct cannot work. When sscanning the association
> > list, when the implementation encounters a nonmatching type,
> > it has to parse the associatead expression in order to find
> > the next clause in the association list.)
> >
> > I would havce designed this with required parentheses:
> >
> > _Generic(expr, t1: (e1), t2: (e2), ... :default (edfl));
> >
> > Only the matching expression would be fully parsed; the non-matching
> > ones would be regarded as token sequences in which parentheses and
> > braces have to balance.
> Another idea is to parse and type check each of the en, but inside each
> one, pretend that expr has the type of tn.
>
> We invent a generated symbol __g0025 and transform
> the construct like this. Here I'm using GCC brace expression
> syntax ({ ... }):
>
> _Generic(expr,
> t1 : ({t1 __g0025 = expr; ee1; }),
> t2 : ({t2 __g0025 = expr; ee2; }),
> // ...)
>
> Here ee2 denotes e1, but with __g0025 substituted for
> expr (so that expr is evaluated only once).
>
> Under this transformation, the ony type error we have
> in the dead clauses occurs in the initialization of
> __g0025 which isn't compatible with tn on the left.
>
> The implementation can arrange to suppress that
> diagnostic, and then just parse and type-check ee2, which has a
> correctly typed __g0025 in scope.

I usually do this why a pointer to void and back to the right type
for the branch
https://godbolt.org/z/4fr37shGn

("usually" = rarely, because I avoid this type of generic
programming because it causes more problems than it
solved)

Note that GCC emitting warnings for the non-active branch
is a known problem. A design problem of _Generic is
that the default branch does not have to be last, so during
parsing it may not be known which branch is active (it
could still suppress warnings when the default branch is
last though).

Another way this could have been solved is to give a new name
to access the value of the controlling expression inside the
branch which then gets the right type:

_Generic(x, int y: y + 1, default: 0);

where y = x for the active branch.

Martin

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor