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,237 of 243,242   
   Waldek Hebisch to Philipp Klaus Krause   
   Re: What is the meaning of array paramet   
   29 Nov 25 22:28:38   
   
   From: antispam@fricas.org   
      
   Philipp Klaus Krause  wrote:   
   > Since C99 we have four types of array parameters:   
   >   
   > []   
   > [assignment-expression]   
   > [static assignment-expression]   
   > [*]   
   >   
   > But what is their meaning? They're all compatible, they all decay to   
   > pointers anyway. Only to [static assignment-expression] does the   
   > standard give a little bit of extra formal meaning, by making it UB when   
   > a too-short array is passed.   
   >   
   > 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.   
      
   AFAICS there are two essentially different cases: normal arrays,   
   that decay to pointers and VMT-s which preserve information about   
   array size.   
      
   AFAICS VMT-s were added mostly as a hack, deemed essential in   
   some application.  But from my point of view definiton was   
   bothed.  Namely, with size in prototype compiler could spot   
   at least some cases of discrepancy between call site and   
   prototype (namly cases when argument in an actual array, so   
   bound info is available).  And could spot mismatches between   
   definiton and prototype.  But apparenty standard makers did   
   not want compilers to check, so they added '*' specifier   
   which signals VMT-s in prototype, but do no provide bounds   
   info and (worse) mandated that VMT-s in prototype should be   
   used as if bound were given as '*'.   
      
   However, based on VMT-s one can still add resonably useful   
   checks to a C compiler.  First, C compier can warn about   
   anything it wants, so compiler can warn about uses of '*'   
   in prototypes.  And can warn about mismatches of size info   
   in prototype and definition and at call site.  Similar   
   thing is possible using 'static' specifier for fixed   
   size arrays.  In non-compliant mode compiler can turn   
   check failures in compile-time errors.   
      
   AFAICS checks as above can signifcanty increase number of   
   memory safe C programs that can be written.  Namely,   
   with normal compiler one can not use arrays or pointers   
   in memory-safe programs, as both are unchecked.  With   
   checking compiler one can safely use visible array, but   
   one can not pass them between functions, because normal   
   parameter passing discards array bounds.  Using C-99   
   parameters one can actually pass arrays and have checking.   
   OK, checking C-90 compiler could use size info, so could   
   handle fixed size array.  But VMT-s allow safe passing of   
   variable sized arrays, which is significant difference.   
      
   --   
                                 Waldek Hebisch   
      
   --- 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