Article View: comp.lang.c
Article #2193Re: Iterators over slices and views and ranges analogs in C
From: David Brown
Date: Fri, 04 Dec 2026 16:14
Date: Fri, 04 Dec 2026 16:14
62 lines
3608 bytes
3608 bytes
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.
Technical Details
Message-ID:
<11euot5$1ogcm$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.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> <11eudm8$1igc3$1@dont-email.me> <a8adndvZlvSgS4_2nZ2dnZfqn_WdnZ2d@giganews.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: Iterators over slices and views and ranges analogs in C Date: Fri, 4 Dec 2026 17:14:28 +0100 Organization: A noiseless patient Spider Lines: 62 Message-ID: <11euot5$1ogcm$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> <11eudm8$1igc3$1@dont-email.me> <a8adndvZlvSgS4_2nZ2dnZfqn_WdnZ2d@giganews.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 04 Dec 2026 16:14:29 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1851798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BVXCgV+QMwpo8VpX4Wqd+qrJvTXqLo0A="; posting-host="f8d429fc41b298b14a9203a87d5618c6" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1EAWCyvVrWtzS9lkpbIoqAiHe6s= sha256:gLZ8XmsahPaGFSRI64t6PktfsQQ89qEoyJ3tbBxfxS4= sha1:6Qlh6sqHVaWUYOc3YyudCximlVE= sha256:MscVgPWEMgVQZ3Y6bMShl5vx5HfW9gB8C41oRIvu5D4= Content-Language: en-GB, nb-NO In-Reply-To: <a8adndvZlvSgS4_2nZ2dnZfqn_WdnZ2d@giganews.com>