Sujet : Re: When Is A High/Low-Level Language Not A High/Low-Level Language?
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 17. Aug 2024, 11:19:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9ptfh$1s7lo$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 16/08/2024 06:58, Lawrence D'Oliveiro wrote:
Here’s a little bit of Python code, from <https://gitlab.com/ldo/inotipy>:
info_type = infoptr.contents.info_type
infoptr = ct.cast \
(
infoptr,
ct.POINTER
(
{
FANOTIFY.EVENT_INFO_TYPE_FID : FANOTIFY.event_info_fid,
FANOTIFY.EVENT_INFO_TYPE_DFID_NAME : FANOTIFY.event_info_fid,
FANOTIFY.EVENT_INFO_TYPE_DFID : FANOTIFY.event_info_fid,
FANOTIFY.EVENT_INFO_TYPE_PIDFD : FANOTIFY.event_info_pidfd,
FANOTIFY.EVENT_INFO_TYPE_ERROR : FANOTIFY.event_info_error,
}[info_type]
)
)
That’s a conditional cast, based on a common header field, to the
appropriate struct type for that data block.
That’s not just a switch-expression, it’s a switch-expression
returning a type.
So, something like:
i = a.b.c
a = cast(a, ptr({x.P:x.p, y.Q:y.q, z.R:z.r}[a]))
But as someone asked, what does this have to do with C, or anything at all? Apart from being an apallingly bit of code.
However I can't see the switch-expression; there is a Dict constructor, where all elements are evaluated, not just the one selected. That is not how 'switch' works.
(Perhaps you're looking for 'match' in Python? Either that or pre-evaluate the {...} expression elsewhere if the contents are fixed.)
If you're suggesting that a 'switch' (a real one) that returns a value is 'high level', then a lower level language can do that too. (I think that gnuC can do so, plus mine of course.)