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


Groups > comp.lang.c > #100829

Re: Automatic null checks

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Automatic null checks
Date 2017-01-01 23:00 +0000
Organization A noiseless patient Spider
Message-ID <87y3yumln1.fsf@bsb.me.uk> (permalink)
References <a12ea453-3855-4ae0-a469-5d4a7e13de33@googlegroups.com> <33078933-d344-4aa3-b6ea-e657c7e28cb5@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com writes:

> On Sunday, January 1, 2017 at 11:53:30 AM UTC-6, Thiago Adams wrote:
>> I am implementing the concept of null checking in 
>> my static analyser.
>
> A fundamental difficulty with non-nullable pointer/reference types, which
> renders absurd the notion that null pointers were a "billion-dollar mistake",
> is that it will often be necessary to read some items out of an array of
> pointers before all members of the array have been written, and *something*
> has to happen if code attempts to read from an array element which has not
> been written.

But something can (and should) always be written.  Other languages deal
with this using a discriminated union or "maybe" type of some sort and
the array is always initially filled with values of the "nothing" type.
The only way to access an element is with a type-checked case statement
(or expression) of some form:

  for (int i = 0; i < A.len; i++)
    case A[i] of
      type nothing: skip;
      type some p: process_pointer(p);

Apologies if this syntax is not clear, I just make it up.

The key difference is that the compiler can check that a NULL pointer is
never used.

<skip>
-- 
Ben.

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


Thread

Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-01 09:53 -0800
  Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-01 10:16 -0800
    Re: Automatic null checks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-01 19:26 +0000
      Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-02 05:56 -0800
        Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-02 08:26 -0800
    Re: Automatic null checks jacobnavia <jacob@jacob.remcomp.fr> - 2017-01-01 22:39 +0100
  Re: Automatic null checks supercat@casperkitty.com - 2017-01-01 14:24 -0800
    Re: Automatic null checks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-01 23:00 +0000
      Re: Automatic null checks supercat@casperkitty.com - 2017-01-01 16:42 -0800
        Re: Automatic null checks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-02 02:08 +0000
          Re: Automatic null checks supercat@casperkitty.com - 2017-01-02 09:38 -0800
            Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-02 10:25 -0800
            Re: Automatic null checks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-02 18:48 +0000
    Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-02 07:45 -0800
  Re: Automatic null checks Les Cargill <lcargill99@comcast.com> - 2017-01-03 07:11 -0600
    Re: Automatic null checks Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 17:43 -0800

csiph-web