🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2195

Re: Iterators over slices and views and ranges analogs in C

#2195
From: Ross Finlayson
Date: Fri, 04 Dec 2026 16:23
91 lines
4675 bytes
On 12/04/2026 08:14 AM, David Brown wrote:
> On 04/12/2026 16:03, Ross Finlayson wrote:
>> On 12/04/2026 05:03 AM, bartc wrote:
>>> On 04/12/2026 12:45, Bonita Montero wrote:
>>>> Am 04.12.2026 um 13:07 schrieb bartc:
>>>>
>>>>>   #define typename(x) (_Generic((x),\
>>>>>       int:                   "int",\
>>>>>       unsigned int:          "unsigned int",\
>>>>>       const int:             "const int",\
>>>>>       default:               "other"))
>>>> Compared to C++ generics this really, really sucks !
>>>>
>>>
>>> How would you do typename(x) in C++ then?
>>>
>>> That is, return the type of expression 'x' as a string (in some
>>> canonical form).
>>>
>>> This is not really generics, but reflection.
>>>
>>> In my language it would be:
>>>
>>>      'x.typestr'
>>>
>>> (With 'x.type' returning a unique ordinal for the type, which can be
>>> used for comparisons etc.)
>>>
>>>
>>
>> Methinks the standard says that according to _Generic construct that
>> cv-qualified types are distinct types with regards generic (_Generic,
>> the "generic" construct in C.
>>
>
> No.  Please read the other posts, or the C standards, or a decent
> reference like <https://cppreference.com/c/language/generic>.
>
>>
>> About the pointer decay (i.e., array-decay-to-pointer), and fixed length
>> arrays, idea seems to be to pass a pointer to the array as
>> controlling-expression.
>>
>> _Generic( &x, \
>> *(int[64]): f_64(x), \
>> *(int[128]): f_128(x), \
>> ) \
>
> That should work, yes.  Test it on godbolt.org.
>
> Alternatively you can wrap your fixed-length arrays in structs.
>
>>
>> Then the idea is that pointer-decay of a pointer to a fixed-length array
>> yet maintains the fixed-length type.
>>
>> Agreeably, the line-continuation line-endings is macro-y and jarring
>> to both readers and parsers.
>>
> The word "agreeably" does not mean what you think it means.  Your Humpty
> Dumpty approach to language makes your posts jarring to readers.
>
>


"Agreeably" means at least two things, it may mean "Agreeably, as in
I'm being agreeable...", or "Agreeably, this is agreeable", then with
regards to what "agreeable" is, it has several meanings, like "this is
agreeable in the sense of aesthetic judgment" or "this is agreeable
and you can take it or leave it" meaning some do and some don't.


Agreeably, it's a usual opinion that macros the line-continuation
line-endings are both un-agreeable and dis-agreeable.


"For each great saying, there's an equal and opposite great saying."
(Samuel Clemens or Mark Twain, also attributed to Apollo.)



About the cv-qualified and those being considered separate types,
yes that surprises me I was under the impression that the _Generic
construct distinguishes among cv- and non-cv-qualified types.

(Saying "was" might still be "is".)


Thanks for writing, warm regards.

Technical Details
Message-ID: <0ESdnXrDxM2_dI_2nZ2dnZfqn_qdnZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <11esd12$mfam$1@raubtier-asyl.eternal-september.org> <11et39b$rj55$1@news.xmission.com> <11ett3b$1a41p$1@dont-email.me> <11euadh$1gp4t$1@dont-email.me> <11euckd$1ht9i$1@raubtier-asyl.eternal-september.org> <11eudm8$1igc3$1@dont-email.me> <a8adndvZlvSgS4_2nZ2dnZfqn_WdnZ2d@giganews.com> <11euot5$1ogcm$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Dec 2026 16:24:01 +0000
Subject: Re: Iterators over slices and views and ranges analogs in C
Newsgroups: comp.lang.c
References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com>
 <11esd12$mfam$1@raubtier-asyl.eternal-september.org>
 <11et39b$rj55$1@news.xmission.com> <11ett3b$1a41p$1@dont-email.me>
 <11euadh$1gp4t$1@dont-email.me>
 <11euckd$1ht9i$1@raubtier-asyl.eternal-september.org>
 <11eudm8$1igc3$1@dont-email.me>
 <a8adndvZlvSgS4_2nZ2dnZfqn_WdnZ2d@giganews.com>
 <11euot5$1ogcm$1@dont-email.me>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Fri, 4 Dec 2026 08:23:18 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <11euot5$1ogcm$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <0ESdnXrDxM2_dI_2nZ2dnZfqn_qdnZ2d@giganews.com>
Lines: 91
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-APje4gYiLtkT+70jIXuNEV3lN0xsocGDzllluQtc/lfLKFh+7KMzDjibM0V2HwYrinV+8nQF5h/Voji!sRaXtamRvZvuo5ySL8zIr/l62yMs42A/72wDG+rppJubGNUnEXWqel4m0h4admIDJlychy2SMLQ=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40