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


Groups > comp.std.c > #1742

Re: Second draft, "Safe arrays and pointers for C"

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.std.c
Subject Re: Second draft, "Safe arrays and pointers for C"
Date 2012-12-17 18:24 -0500
Organization A noiseless patient Spider
Message-ID <kao9kc$9bb$1@dont-email.me> (permalink)
References <503FC37F.8050701@animats.com> <be6d64cd-2553-48e7-99b4-c0742b611119@googlegroups.com> <k44qnl$k3t$1@dont-email.me> <kan97e$h4n$1@dont-email.me> <lnobhsilu6.fsf@nuthaus.mib.org>

Show all headers | View raw


On 12/17/2012 13:18, Keith Thompson wrote:
> Shao Miller <sha0.miller@gmail.com> writes:
>> On August 30th, 2012, at 12:23:29, John Nagle published:
>>> Safe arrays and pointers for C through compatible additions to the language
>>
>> Some feed-back, if you care:
>>
>> I don't really care for importing references from C++11.  C has long
>> passed by value (with the exception of arrays [which itself has an
>> exception in C89/C90]).
>
> Strictly speaking, arrays are not an exception to the C rule that
> function arguments are passed by value.  Given
>
>      int arr[N];
>      func(arr);
>
> an array is not being passed as an argument; rather, a pointer is
> being passed (by value, of course).  The implicit conversion of
> the array expression to a pointer is unrelated to the fact that
> it appears in a function call; the same conversion happens in
> most contexts.

Yes; thanks.  The omission of ", which aren't passed at all" before the 
space just before the left square bracket was an unhelpful one.

>
> [...]
>
> If C were to add some kind of pass-by-reference mechanism (other than
> the existing pass-a-pointer-by-value), it might be useful to require
> some distinguishing syntax on the call.  For example, assuming the
> addition of a "ref" keyword:
>
>      void increment(ref int n) {
>          n ++;
>      }
>
>      int x = 42;
>      /* increment(x); would be illegal */
>      increment(ref x);
>      /* now x == 43 */
>

While I agree that distinguishing syntax is desirable, I don't quite 
follow what the advantage of that particular example is, over pointers. 
  (Of course, that mightn't've been a demonstration of an advantage, but 
simply of distinguishing syntax.)

What I don't quite understand about the proposal (yet, but there's more 
for me to read) is the benefit.  Since the size of an array (or count of 
its elements) isn't _always_ needed (sentinel values, for example), why 
try to tie it more closely to arrays?  I'll re-emphasize _always_, just 
now; a nice-to-have, _if_ you want it.

It seems that the major issue being addressed is buffer overflow, some 
of which could be caught at translation-time (as a form of type-safety?) 
and some of which could be caught at run-time (as a form of run-time 
type-checking?).  Isn't that what C99's 'static' in an "array" (but 
really pointer) parameter declaration in a function declaration was for?

Perhaps it'll be clearer after reading the rest of the proposal. :)

- Shao Miller

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


Thread

Second draft, "Safe arrays and pointers for C" John Nagle <nagle@animats.com> - 2012-08-30 12:48 -0700
  Re: Second draft, "Safe arrays and pointers for C" pacman@kosh.dhis.org (Alan Curry) - 2012-08-31 22:17 +0000
    Re: Second draft, "Safe arrays and pointers for C" John Nagle <nagle@animats.com> - 2012-08-31 17:26 -0700
      Re: Second draft, "Safe arrays and pointers for C" Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-09-02 22:20 +0200
        Re: Second draft, "Safe arrays and pointers for C" BGB <cr88192@hotmail.com> - 2012-09-03 10:55 -0500
          Re: Second draft, "Safe arrays and pointers for C" Ike Naar <ike@iceland.freeshell.org> - 2012-09-03 16:39 +0000
            Re: Second draft, "Safe arrays and pointers for C" BGB <cr88192@hotmail.com> - 2012-09-03 13:18 -0500
  Re: Second draft, "Safe arrays and pointers for C" Jens Gustedt <jens.gustedt@loria.fr> - 2012-09-02 10:52 +0200
  Re: Second draft, "Safe arrays and pointers for C" Per <per.mathisen@gmail.com> - 2012-09-28 06:49 -0700
    Re: Second draft, "Safe arrays and pointers for C" John Nagle <nagle@animats.com> - 2012-09-28 11:36 -0700
      Re: Second draft, "Safe arrays and pointers for C" Per <per.mathisen@gmail.com> - 2012-10-01 09:38 -0700
        Re: Second draft, "Safe arrays and pointers for C" John Nagle <nagle@animats.com> - 2012-10-01 11:38 -0700
      Re: Second draft, "Safe arrays and pointers for C" Shao Miller <sha0.miller@gmail.com> - 2012-12-17 09:11 -0500
        Re: Second draft, "Safe arrays and pointers for C" Keith Thompson <kst-u@mib.org> - 2012-12-17 10:18 -0800
          Re: Second draft, "Safe arrays and pointers for C" Shao Miller <sha0.miller@gmail.com> - 2012-12-17 18:24 -0500
            Re: Second draft, "Safe arrays and pointers for C" Shao Miller <sha0.miller@gmail.com> - 2012-12-17 18:32 -0500
            Re: Second draft, "Safe arrays and pointers for C" Keith Thompson <kst-u@mib.org> - 2012-12-17 15:44 -0800

csiph-web