Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #68701

Re: who invented static?

Subject Re: who invented static?
Newsgroups comp.lang.c
References (3 earlier) <6036cc6f-2804-45c2-95f4-e19a5fa9399d@googlegroups.com> <55E21F50.2080705@verizon.net> <mrv5f3$g9b$1@dont-email.me> <55E32CBB.2050001@verizon.net> <mrvcnh$fju$1@dont-email.me>
From Richard Damon <Richard@Damon-Family.org>
Message-ID <m_GEx.8461$1H1.2009@fx23.iad> (permalink)
Organization Forte - www.forteinc.com
Date 2015-08-30 13:23 -0400

Show all headers | View raw


On 8/30/15 1:00 PM, David Brown wrote:
> On 30/08/15 18:18, James Kuyper wrote:
>> On 08/30/2015 10:56 AM, David Brown wrote:
>>> On 29/08/15 23:08, James Kuyper wrote:
>>>
>>>> The following use of "static" is new in C99, and can only occur in the
>>>> leading dimension of a function parameter declared as an array:
>>>> "If the keyword static also appears within the [ and ] of the array
>>>> type
>>>> derivation, then for each call to the function, the value of the
>>>> corresponding actual argument shall provide access to the first element
>>>> of an array with at least as many elements as specified by the size
>>>> expression." 6.7.6.3p7
>>>>
>>>> This obviously should have no counterpart in K&R C.
>>>>
>>>
>>> This last use of "static" is completely new to me.  I can see the
>>> corresponding paragraph in the C11 standards (since that's the one I
>>> have handy), but I can't figure out what it means or what it is for.
>>
>>
>> Given:
>>
>>      void f(int array[static 3]);
>>      int large_array[6];
>>      int small_array[2];
>>      int *p = small_array;
>>
>> then f(large_array) is fine, because large_array has more than 3
>> elements. However, f(small_array) violates a "shall" that occurs outside
>> of a constraint, because small_array has fewer than 3 elements. The
>> behavior is therefore undefined. I would have preferred that this be a
>> constraint violation, and I would expect any decent implementation of
>> C99 or later to issue the diagnostic message that would be mandatory if
>> it were a constraint violation - in my opinion, that possibility is the
>> only thing that makes this feature worthwhile. I think that the reason
>> why it cannot be made a constraint violation is that f(p) is also a
>> violation of the same rule, and unlike f(small_array), it's not in
>> general easy for a compiler to identify the fact that an arbitrary
>> pointer points at location which violates this rule.
>>
>
> But surely if g were defined:
>
>      void g(int array[3]);
>
> Then g(small_array) would still be a constraint violation?  Or is it
> defined behaviour to call g(small_array), and only becomes undefined if
> g() accesses array[2] ?
>
> It seems to me that even without the "static", g is asking for a
> parameter with particular characteristics, and calling g(small_array) is
> breaking that requirement.
>

in c, this definition of g is IDENTICAL to (by a rewrite rule)
   void g(int *array);

(note, the 3 is lost)
Thus, the passing of anything that is an int* or decays to an int* (like 
an array of any size of int) is valid.

Adding the static keyword changes the type of that parameter so that the 
compiler actually remembers the needed bounds, and will check that the 
passed array is large enough.

> It also seems to me to be a /really/ odd choice to make this another use
> of the "static" keyword.  If a keyword is needed here (I think the
> "static" behaviour is the only sensible one, and should be the case
> without the keyword), then I would go for a new keyword such as
> "__I_really_mean_it" :-)
>

This is one of the cases where the Standards Committee decided that it 
was better to reuse an old keyword in a different context rather than 
needing to come up with a new "ugly" (to be backwards compatible) keyword.

Note, that the conversion of arrays to pointers in this context goes all 
the way back to K&R (and earlier) in the 70's and changing the behavior 
would break a number of programs, so it couldn't be made the default.

>
> Is this a use of "static" that you have seen in real code?  Is it used
> much?
>
> Thanks,
>
> David
>

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

who invented static? fir <profesor.fir@gmail.com> - 2015-08-29 11:40 -0700
  Re: who invented static? David Kleinecke <dkleinecke@gmail.com> - 2015-08-29 13:36 -0700
    Re: who invented static? fir <profesor.fir@gmail.com> - 2015-08-29 13:46 -0700
      Re: who invented static? David Kleinecke <dkleinecke@gmail.com> - 2015-08-29 13:53 -0700
        Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-08-29 17:08 -0400
          Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-08-30 16:56 +0200
            Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-08-30 12:18 -0400
              Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-08-30 19:00 +0200
                Re: who invented static? Richard Damon <Richard@Damon-Family.org> - 2015-08-30 13:23 -0400
                Re: who invented static? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-30 21:18 +0100
                Re: who invented static? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-06 19:33 -0700
                Re: who invented static? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-06 19:26 -0700
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-08-30 13:40 -0400
                Re: who invented static? supercat@casperkitty.com - 2015-08-31 06:47 -0700
                Re: who invented static? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-06 19:20 -0700
                Re: who invented static? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-06 18:59 -0700
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-07 10:25 +0200
                Re: who invented static? Keith Thompson <kst-u@mib.org> - 2015-09-07 01:59 -0700
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-07 12:22 +0200
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-09-07 13:04 -0400
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-07 21:25 +0200
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-09-07 15:47 -0400
                Re: who invented static? Philip Lantz <prl@canterey.us> - 2015-09-07 13:27 -0700
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-09-07 17:31 -0400
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-08 09:16 +0200
                Re: who invented static? Keith Thompson <kst-u@mib.org> - 2015-09-07 13:27 -0700
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-08 09:12 +0200
                Re: who invented static? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-07 16:06 -0700
                Re: who invented static? David Brown <david.brown@hesbynett.no> - 2015-09-08 09:08 +0200
                Re: who invented static? Keith Thompson <kst-u@mib.org> - 2015-09-08 10:18 -0700
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-09-08 13:28 -0400
        Re: who invented static? fir <profesor.fir@gmail.com> - 2015-08-29 14:18 -0700
          Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-01 01:36 -0700
    Re: who invented static? Keith Thompson <kst-u@mib.org> - 2015-08-29 14:27 -0700
  Re: who invented static? Siri Cruz <chine.bleu@yahoo.com> - 2015-08-29 14:32 -0700
    Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-29 23:03 +0000
    Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-01 01:52 -0700
      Re: who invented static? Robert Wessel <robertwessel2@yahoo.com> - 2015-09-01 23:42 -0500
        Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-02 00:14 -0700
          Re: who invented static? Richard Heathfield <rjh@cpax.org.uk> - 2015-09-02 08:24 +0100
        Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-04 04:25 +0000
          Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-04 00:45 -0700
            Re: who invented static? Robert Wessel <robertwessel2@yahoo.com> - 2015-09-04 04:09 -0500
              Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-04 02:35 -0700
                Re: who invented static? Robert Wessel <robertwessel2@yahoo.com> - 2015-09-04 23:58 -0500
                Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-05 03:02 -0700
                Re: who invented static? wssimms@gmail.com - 2015-09-05 13:14 -0700
                Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-05 13:49 -0700
                Re: who invented static? Siri Cruz <chine.bleu@yahoo.com> - 2015-09-05 14:09 -0700
                Re: who invented static? gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-05 22:30 +0000
                Re: who invented static? wssimms@gmail.com - 2015-09-05 20:41 -0700
                Re: who invented static? gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-06 05:28 +0000
                Re: who invented static? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-05 22:40 -0700
                Re: who invented static? James Kuyper <jameskuyper@verizon.net> - 2015-09-06 11:42 -0400
                Re: who invented static? Robert Wessel <robertwessel2@yahoo.com> - 2015-09-05 23:38 -0500
            Re: who invented static? Siri Cruz <chine.bleu@yahoo.com> - 2015-09-04 02:34 -0700
              Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-04 02:43 -0700
              Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-05 01:30 +0000
                Re: who invented static? Siri Cruz <chine.bleu@yahoo.com> - 2015-09-04 20:52 -0700
                Re: who invented static? Robert Wessel <robertwessel2@yahoo.com> - 2015-09-05 00:03 -0500
                Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-05 09:04 +0000
                Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-05 03:02 -0700
                Re: who invented static? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-05 04:33 -0700
                Re: who invented static? Reinhardt Behm <rbehm@hushmail.com> - 2015-09-05 20:08 +0800
                Re: who invented static? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-05 05:21 -0700
                Re: who invented static? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-05 06:37 -0700
                Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-05 16:54 +0000
                Re: who invented static? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-05 11:06 +0100
                Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-05 03:17 -0700
                Re: who invented static? raltbos@xs4all.nl (Richard Bos) - 2015-09-05 19:14 +0000
                Re: who invented static? fir <profesor.fir@gmail.com> - 2015-09-05 12:59 -0700
            Re: who invented static? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-05 01:24 +0000

csiph-web