Sujet : Re: Code guidelines
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 04. Sep 2024, 15:02:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240904065353.553@kylheku.com>
References : 1 2 3 4 5 6
User-Agent : slrn/pre1.0.4-9 (Linux)
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.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca