🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2188

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

#2188
From: Ross Finlayson
Date: Fri, 04 Dec 2026 15:21
115 lines
7038 bytes
On 12/04/2026 06:38 AM, David Brown wrote:
> On 04/12/2026 14:58, Janis Papanagnou wrote:
>> On 2026-12-04 13: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 !
>>
>> Grafting features to a language that wasn't designed to support
>> those regularly often lead to clumsy, ugly, inconsistent designs.
>> So while it's not surprising, but it also won't change what "C"
>> actually is (and what's discussed here, the C-language).
>
> I don't think _Generics are clumsy, ugly or inconsistent - they are
> actually quite clear and simple.  But they do get bulky if you want to
> support more than one parameter.
>
> _Generic's are a lot more limited than C++ templates or overloaded
> functions, but adding those to C would be a massive change as they
> fundamentally change what is meant by "a function".
>
>>
>> What I'm wondering about, though, is what the actual "customers"
>> for such features in "C" are, and what the "vendors" (compiler
>> writers and standards people) think when introducing such things.
>> Upthread it had been speculated (by David) that this feature is
>> probably "underused", and another comment (from Bart) hinted on
>> a non-obvious restriction (in implementations or the standard).
>> Folks who want something better designed, more consistent, with
>> cleaner syntax, and with less restrictions and arguable choices,
>> might choose to use C++ (or something else).
>>
>> So, who are the "C" clients for whom this feature is important?
>>
>
> These are fair questions.
>
> I think the immediate answer for _Generic is that it would be useful to
> anyone who saw <tgmath.h> in C99 and thought "I wish I could do that".
> It is thus much more likely to be useful to library authors than
> application programmers.
>
> That also applies to implementations of the C standard library.  So
> while in C99 you needed <tgmath.h> implemented with compiler magic, with
> C23 I would expect plain portable C could be used for the new <stdbit.h>
> functions.
>
> I have used _Generic a couple of times in "libraries of small useful
> functions", but never in a way that made a significant difference.
> However, I primarily use C++ for most of my code these days and most of
> my C projects are in C99 rather than C11, so _Generic is neither
> available nor needed.  But there are times where I use templates and/or
> overloading in C++ in my code, where I might have used _Generic had I
> been coding in C.  (It's difficult to be sure, as the structure of the
> code could be significantly different in C.)
>
>
>> N.B.: I've been heavily using C++ polymorphism in sophisticated
>> designs but never(?) needed RTTI. (Clean OO-programming made it
>> unnecessary to switch on types.) I used generic data structures
>> a lot in C++, though, and their advantages (compared to "C")
>> are obvious. I also never needed introspection. - I guess it's
>> depending on the programming paradigms one chooses.
>>
> I not only have never needed RTTI, but I have it disabled - for small
> systems embedded use, "-fno-rtti" and "-fno-exceptions" are very common.
>   I think RTTI is perhaps more important if you have complicated
> exceptions in code - exception types can be passing through your
> handlers that don't really know much about the types being thrown.
>
> Once I am able to make use of C++26 and reflection in my code, I can
> definitely see use-cases for it.  At the very least, my debug printfs
> will have nicer output for enumeration types :-)
>
>

I don't know, "Lombok" in Java has various accounts. (The "Lombok"
compiler-plugin is present in quite most many Java builds, it generates
boilerplate like "default operators" of equals/hashCode and
getters/setters" and "toString.) Agreeably accounts of compile-time
reflection is quite an involved round-trip in compilation. (Java's
account of enum and making toString since keeping around its identifier
as like a class-variable is agreeably well-thought-out and of a unified
sort of approach like the rest of Java is, that C++ has become a
sort of "designed-by-more-than-one-committee" vis-a-vis
"designed-by-committee".)

The syntax of templates & sources together quite rather involved,
like that it's two separate dialects with two separate tools.

RTTI is fantastic for accounts of polymorphism and the parallel
in Java instanceof then as for reflection, has that I've written
quite a few modules in many uses of reflection, run-time, according
to class-literals being compiled type-safe, at compile-time. For
example over on comp.lang.java.programmer is an outline of an entire
sort of web-caller framework like for HTTP with Spring or Jersey,
"Signature" sort of approach.




There's _Generic which some say is C99 then there's auto which
some aver is C23, yet, there's __auto_type and _Generic together
about C11 with gcc etc., with carrying the type for type-induction
for type-inference, that being the feature in the language.




Technical Details
Message-ID: <i5-dnSCmSLz7R4_2nZ2dnZfqnPqdnZ2d@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-1.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> <11eugtg$erg$4@dont-email.me> <11euj8b$1lhf1$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-1.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 15:21:10 +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>
 <11eugtg$erg$4@dont-email.me> <11euj8b$1lhf1$1@dont-email.me>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Fri, 4 Dec 2026 07:21:07 -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: <11euj8b$1lhf1$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <i5-dnSCmSLz7R4_2nZ2dnZfqnPqdnZ2d@giganews.com>
Lines: 115
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-jXo5tHo3Se0lsN2w9S1Ql5pMCFwLncOS4qyLjV10iSKUkxnuYq/TKS9dvnmsDWQkvHJny80B0Lrye3A!EHatrwm57XREqujZW07fXGk3KkxvSsLTcUrMnb7p9usxpyTTgmN8sss7Xnig7Z5nS1FKEpCIjcs=
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