🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2202

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

#2202
From: Ross Finlayson
Date: Fri, 04 Dec 2026 18:02
247 lines
12786 bytes
On 12/04/2026 09:44 AM, David Brown wrote:
> On 04/12/2026 17:55, Ross Finlayson wrote:
>> On 12/04/2026 08:33 AM, David Brown wrote:
>>> On 04/12/2026 16:21, Ross Finlayson wrote:
>>>> 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 :-)
>>>>>
>>>>>
>>>>
>>>
>>> Please stop trying to compete with AI in producing incomprehensible
>>> slop.
>>>
>>>>
>>>> There's _Generic which some say is C99
>>>
>>> Nobody says that _Generic is in C99.  It was added to C in C11.
>>>
>>>> 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.
>>>>
>>> If I understand your word salad correctly, you are saying that gcc had
>>> "__auto_type" before type inference with "auto" was added to standard C
>>> in C23.  That would be correct.  It would be wrong to say or imply that
>>> it was ever part of C11 - when gcc started supporting it, they did so as
>>> a gcc extension that is independent of the C standard chosen.  It was
>>> added in gcc 5, some time after C++11 support of "auto" for type
>>> inference.  The gcc extension "typeof" has been around since at least
>>> gcc 2.9 (which is as far back as it is convenient to check gcc manuals).
>>>
>>> I don't know what you mean by "type-induction" - it looks like you are
>>> just using made-up words again.
>>>
>>>
>>
>>
>> Thanks for writing. The _Generic construct was implemented for quite
>> a while before C11, yes that it's in C11.
>
> _Generic was added to C in C11.  Not before.
>
> It is not uncommon for compilers to have early support for features that
> are expected to be added to in upcoming standard versions.  Indeed for
> major features, it is the norm for them to be experimentally tested in
> major compilers before standardisation.  And a number of features of C
> and C++ standards started off as extensions in one or more compilers.
>
> But _Generic was not added to gcc until 4.9, released in 2014.  C11
> support was introduced gradually from 4.6 to 4.9, with a few pre-release
> parts in 4.5.
>
> <https://gcc.gnu.org/projects/c-status.html#c11>
>
> (Or see the individual references for gcc versions.)
>
> If you have reason to say that _Generic was implemented "quite a while
> before C11", then please give references - not "proof by repeated
> assertion".  I have only checked gcc history, since that is the compiler
> I am most familiar with and it has been named in this discussion.  It is
> entirely possible that some other compilers had _Generic implementations
> earlier and before the finalisation of the C11 standard - if you believe
> that to be so, please support the claim.
>
>>
>> About "type-induction", that's simply enough the transitivity of type,
>> that "type-inference" most usually uses the "type-induction" as the
>> property of "having a type".
>
> As I suspected - meaningless word salad.
>
>>
>> Then "auto" is implemented (as __auto_type since shortly after C11,
>> in gcc or equivalently in others), and is in C23, is so. (Notice the
>> first clause is "implicitly quoted", about quoting-context and so on.)
>>
>
> gcc's "__auto_type" was inspired by C++11's new use of "auto" for type
> inference.  (That is type /inference/ - not "type induction".)  Roughly
> speaking, they made C++11's "auto" available in C as an extension.  C11
> had nothing to do with it.
>
>
> (I've snipped the rest of your jumble.  To the extent that it had any
> meaningful interpretation, it's pretty much entirely wrong.  You should
> stop reading books about philosophy or logic - you don't understand what
> they are saying, and it looks silly when you use the words you found
> incorrectly, out of context, and with added random hyphens.)
>
>>
>> Then, I went looking for anything else in C that has to do with
>> type and introducing types or discriminating among types, there's
>> basically the _Generic construct and __auto_type in C11 + gcc,
>> where the types are built-ins or fixed-length-arrays or for
>> struct/union/enum or pointers thereto, with typedef making
>> aliases not introducing types.
>>
>> Then there are expressions _about_ expressions in type,
>> like sizeof and offsetof if not so much typeof, that I'd
>> wonder more about typeof, yet I don't gather the use of typeof.
>>
>
> Since you are now talking about C, I am /trying/ to understand what you
> attempting to say.  It doesn't look like a question, so I can't answer
> it.  And since I can't figure out what you are trying to say, I can't
> tell you if it is right or wrong.
>
>>
>>
>> Perhaps we could talk about typeof, ..., and decltype is
>> considered _not_ in the language. Here though there
>> are _Generic and auto, for maintaining type-induction
>> so type-inference carries.
>>
> /Why/ do you write crap like this?  Surely you /know/ that C does not
> have "decltype" ?  There's no "considered" involved.
>
> If you want to talk about "typeof", go ahead.  Ask what you want to know.
>
> I just have one small request.  Once you have written your post, before
> pressing "send", look through it.  Every time you have used the word
> "agreeably", delete the whole paragraph.  Do the same every time you
> have written a word with a hyphen, referred to "induction", used the
> phrase "vis-a-vis", or written more than four lines in one sentence. The
> text left after that cull will make a lot more sense and give people a
> chance to understand your question, and answer it.
>
>

Oh, decltype has snuck its way into compiling C.
It's to be avoided, for example with aliasing "gcc"
to "gcc -std=c11" or "gcc -std=gnu11".

I don't need an "always-online oracle", I have one right here.


If you don't like what I say about logic and so on,
mostly I just make a paleo-classical post-modern
account of the usual sorts of classical expositions
of the super-classical, I have copies of Hegel and Aristotle
here for "Hegelian logic" and "Aristotlean logic".
(Not "merely-partial half-accounts of neo-Hegelians
and neo-Aristotleans.) So, I just point out where
they say so what I say so, about all what they say so.
(I've made a study of "Foundations" for a few decades.)

About type-induction and type-inference and what makes
type-deduction and other accounts of type-inference,
that's simple and "in the language", including,
"in the theory", about mathematical induction and type-theory,
making simple proofs for type-inference via induction.


is-a has-a, ....


Agreeably, which may mean with a cheerful demeanor,
you can take it or leave it that's an opinion.





Technical Details
Message-ID: <ZYKdnah1_NuwnY72nZ2dnZfqnPidnZ2d@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-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-4.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> <i5-dnSCmSLz7R4_2nZ2dnZfqnPqdnZ2d@giganews.com> <11eupvu$1p0q1$1@dont-email.me> <0HydndKd_6bFbY_2nZ2dnZfqn_GdnZ2d@giganews.com> <11euu5h$1ra9d$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-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 04 Dec 2026 18:02:21 +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>
 <i5-dnSCmSLz7R4_2nZ2dnZfqnPqdnZ2d@giganews.com>
 <11eupvu$1p0q1$1@dont-email.me>
 <0HydndKd_6bFbY_2nZ2dnZfqn_GdnZ2d@giganews.com>
 <11euu5h$1ra9d$1@dont-email.me>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Fri, 4 Dec 2026 10:02:08 -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: <11euu5h$1ra9d$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <ZYKdnah1_NuwnY72nZ2dnZfqnPidnZ2d@giganews.com>
Lines: 247
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-sNWTKSKcdzSSiT0hMlCV1qNjxbQXyTFh3V9EwkAWceIQkUc6Ly6GFIDptULh4dt5/LCxgXdM+m333t/!06Pu9aTJHufQKXc9iduxi0la93Sb8IPeIBXp2cSqjtevuwbJAvRmxXxAgGUAN+jqWxg+O7UrRw8=
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