[HN Gopher] Improving _Generic in C2y
       ___________________________________________________________________
        
       Improving _Generic in C2y
        
       Author : luu
       Score  : 26 points
       Date   : 2024-08-04 07:46 UTC (15 hours ago)
        
 (HTM) web link (thephd.dev)
 (TXT) w3m dump (thephd.dev)
        
       | fanf2 wrote:
       | The article describes two problems with _Generic.
       | 
       | There is a third: the discarded branches must typecheck. (Unlike
       | C++ templates, where substitution failure is not an error.) Simon
       | Tatham described the issue in more detail:
       | 
       | https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-g...
        
         | fweimer wrote:
         | There's also the macro expansion/amplification issue (explained
         | at the end of the page you reference). _Generic seems a dead
         | end, it doesn't even work in practice for <tgmath.h>.
        
         | o11c wrote:
         | There's also the fact that the bodies must be expressions, so
         | it's only useful with GNU statement expressions.
         | 
         | Still, since we have __VA_OPT__ and typeof, standard C has
         | gotten to the point of being _almost_ usable ...
        
         | fuhsnn wrote:
         | In its current form without at least requiring balanced
         | enclosing brackets, dropping the semantic check will make
         | _Generic a new macro expansion system worthy of a dedicated
         | round of obfuscated C contest.
        
       | colonwqbang wrote:
       | Nice, does this mean we can have const-generic accesors now? I.e.
       | &s->somefield and get a const pointer if s was a const pointer,
       | but a mutable one otherwise? I guess we still need to define two
       | functions though, but that can probably be handled by macros.
       | This is something that really hinders use of const in current C.
        
       | brcmthrowaway wrote:
       | Wow, I can't believe they wasted a decade on 2 releases
       | 
       | Move fast!
        
         | kats wrote:
         | Don't move fast. This is the C programming language. The
         | foundation of all software. Each new feature will interact with
         | everything else, because C is connected to almost everything
         | else. Making C larger is actually a really bad thing.
        
       ___________________________________________________________________
       (page generated 2024-08-04 23:00 UTC)