home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 241,281 of 243,242   
   David Brown to BGB   
   Re: Nice way of allocating flexible stru   
   10 Oct 25 12:06:10   
   
   From: david.brown@hesbynett.no   
      
   On 10/10/2025 08:27, BGB wrote:   
   > On 10/9/2025 10:59 PM, Keith Thompson wrote:   
   >> bart  writes:   
      
   >>   
   >>>> One merit is if code can be copy-pasted, but if one has to change   
   >>>> all instances of:   
   >>>>     char *s0, *s1;   
   >>>> To:   
   >>>>     char* s0, s1;   
   >>>> Well, this is likely to get old, unless it still uses, or allows C   
   >>>> style declaration syntax in this case.   
   >>>   
   >>> That one's been fixed (50 years late): you instead write:   
   >>>   
   >>>   typeof(char*) s0, s1;   
   >>>   
   >>> But you will need an extension if it's not part of C23.   
   >>   
   >> Yes, that will work in C23, but it would never occur to me to   
   >> write that.  I'd just write `char *s0, *s1;` or, far more likely,   
   >> define s0 and s1 on separate lines.  Using typeof that way triggers   
   >> my WTF filter.   
   >>   
   >   
   > Agreed.   
   >   
   >   
   >   
   > I think it can be contrast with C# style syntax (with "unsafe") where   
   > one would write:   
   >    char* s0, s1;   
      
   Does C# treat s1 as "char*" in this case?  That sounds like an   
   extraordinarily bad design decision - having a syntax that is very like   
   the dominant C syntax yet subtly different.   
      
   Issues like this have been "solved" for decades - in the sense that   
   people who care about their code don't make mistakes from mixups of   
   "char" and "char*" declarations.  There are a dozen different ways to be   
   sure it is not an issue.  Simplest of all is a style rule - never   
   declare identifiers of different types in the same declaration.  I'd   
   have preferred that to be a rule baked into the language from the start,   
   but we all have things we dislike about the C syntax.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca