Article View: comp.lang.c
Article #2250Re: Iterators over slices and views and ranges analogs in C
From: Janis Papanagnou
Date: Sat, 05 Dec 2026 14:36
Date: Sat, 05 Dec 2026 14:36
107 lines
6313 bytes
6313 bytes
On 2026-12-04 15:38, 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. That's fair. I actually was referring to things like the example above (using it with macros!), and statements that I found that C-generics - to "make most sense" - would be used with macros. (Myself, I cannot judge.) > > _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. That makes sense. Thanks. > > 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.) I see. > >> 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 suppose you've done that only because of the application domain you are or were working in. (When we had started with C++ in our professional development we had neither RTTI nor exceptions available. With exceptions we'd not have had necessity to implement an own framework and company standard for that. It would certainly have been useful.) > 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. (I don't see how that would be imposed by the use of exceptions.) > > 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 :-) Yes, that's true; to spare you writing a bit own code to write in this case. Janis
Technical Details
Message-ID:
<11f17h5$2dad1$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<-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!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Iterators over slices and views and ranges analogs in C Date: Sat, 5 Dec 2026 15:36:21 +0100 Organization: A noiseless patient Spider Lines: 107 Message-ID: <11f17h5$2dad1$1@dont-email.me> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 05 Dec 2026 14:36:22 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2533793"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mMfLT0/oCpxdUYGZcgzW9"; posting-host="89c37fd5d8f581f1579ba8626b33c1d2" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:kNPhylA5qD6BrHV3fz4x+BSeiv8= sha256:AIFNzGp3Ru2pg0aYBDwbRtXKmoMpHnVbTV+/5UBnooI= sha1:rwAw+poCKFqHS2HsX8Ma113g8+Y= sha256:mzeWBDMgxPzzi+3wocy8Q2rWdpuId5mU1qJiOln6NW0= Content-Language: en-US In-Reply-To: <11euj8b$1lhf1$1@dont-email.me>