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 242,343 of 243,242   
   Andrey Tarasevich to Philipp Klaus Krause   
   Re: What is the meaning of array paramet   
   05 Dec 25 06:01:36   
   
   From: noone@noone.net   
      
   On Tue 11/25/2025 5:28 AM, Philipp Klaus Krause wrote:   
   > They exist, they are different types, but the standard does not give   
   > them meaning (with the exception noted above). So people using them must   
   > have a motivation beyond what is explicitly stated in the standard, and   
   > thus an idea of what the meaning of these would or should be.   
      
   There's one subtle detail when it comes to treatment of such parameters   
   in C. It is too little to pass for "motivation"... but it is there.   
      
   As you correctly stated, such parameters decay to pointers. However,   
   pointers can point to _incomplete_ types, while arrays can only be built   
   from _complete_ types. C language happens to insist on the array element   
   completeness _before_ adjusting such array parameters to pointers. For   
   which reason the following code is invalid:   
      
      struct S; /* incomplete type */   
      
      void foo(struct S s[]) /* ERROR: element type is incomplete */   
      {}   
      
   (BTW, in C++ the same code would compile without any issues. I believe   
   there was an intent to bring C in sync with C++ on that matter, but it   
   is still there in C23.)   
      
   --   
   Best regards,   
   Andrey   
      
   --- 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