Date: Sun, 3 Aug 2025 20:19:03 +0100
On Sunday, August 3, 2025, David Brown wrote:
>
>>
> What use would that be? If the programmer knows that a pointer in the
> function might be a null pointer, and wants to throw if that is the case,
> then the programmer can write "if (!p) throw nullptr;", or whatever suits
> their needs.
>
It would allow us to write one-liner functions like:
unsigned GetCOMportNumber(char const *const p)
{
return stoul( strstr(p, "COM") + 3 );
}
and also to write a one-liner like:
pInterface1->GetInterface2()->LastChild()->Release();
instead of:
if ( nullptr == pInterface1 ) return;
auto p = pInterface1->GetInterface2();
if ( nullptr == p ) return;
auto p2 = p->LastChild();
if ( nullptr == p2 ) return;
p2->Release();
>
>>
> What use would that be? If the programmer knows that a pointer in the
> function might be a null pointer, and wants to throw if that is the case,
> then the programmer can write "if (!p) throw nullptr;", or whatever suits
> their needs.
>
It would allow us to write one-liner functions like:
unsigned GetCOMportNumber(char const *const p)
{
return stoul( strstr(p, "COM") + 3 );
}
and also to write a one-liner like:
pInterface1->GetInterface2()->LastChild()->Release();
instead of:
if ( nullptr == pInterface1 ) return;
auto p = pInterface1->GetInterface2();
if ( nullptr == p ) return;
auto p2 = p->LastChild();
if ( nullptr == p2 ) return;
p2->Release();
Received on 2025-08-03 19:19:06