Deutsch   English   Français   Italiano  
<vba8e8$3u4jc$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: Code guidelines
Date: Wed, 4 Sep 2024 20:20:55 +0200
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <vba8e8$3u4jc$3@dont-email.me>
References: <vb6v1t$3b5mb$1@dont-email.me> <vb726n$3b4rq$1@dont-email.me>
 <vb736j$3b5mb$2@dont-email.me> <vb75g9$3bntp$1@dont-email.me>
 <vb77tn$3bu07$3@dont-email.me> <vb7d6l$3d5mv$1@dont-email.me>
 <20240904065353.553@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 04 Sep 2024 20:20:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="007bf4bb57fea4fb73ad9dc6d5dccf66";
	logging-data="4133484"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+x/9R8vp8d/1aOLikwP3kL0LDU3GTfWAA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:T/v4YgIluyMRfKeBOLEQhnbXjjw=
In-Reply-To: <20240904065353.553@kylheku.com>
Content-Language: en-GB
Bytes: 2845

On 04/09/2024 16:02, Kaz Kylheku wrote:
> On 2024-09-03, Thiago Adams <thiago.adams@gmail.com> wrote:
>> The contract is
>>
>>    * obj->member1                   CAN be null
>>    * obj->member1->member2          CANNOT be null
>>    * obj->member1->member2->member3 CAN be null
> 
> Newer languages have null-safe object access operators:
> 
>    if (obj?->member1->member2?->member3) ...
> 
> We get the correct check, and, at a glance, the question marks annotate
> what the coder believes is the contract: obj may be null,
> obj->member1->member2 may be null.
> 
> GCC could easily get this extension, it seems.
> 
> obj?->member   is just    obj ? obj->member : nullptr    except that
> obj is evaluated only once.
> 
> 

gcc is not as keen on making new extension syntax as it was some 30 year 
ago.  They try to keep extensions to a minimum, or fitting them into 
existing patterns (__builtin functions and __attribute__'s).  Or they 
import new features from later C or C++ standards back to older standard 
versions.

And they tend to have the attitude that programmers who want a language 
that does more than current C, will probably use a different language. 
In C++ you can often specify non-null requirements using references 
rather than pointers, and it's not hard to make a little class template 
that act mostly like a pointer except that it checks for null first and 
throws an exception on null.  (Making something that will chain like 
your code, resulting in a bool true if everything is good to go, is I 
believe possible but a bit more fiddly.  Ask for details down the hall.)