comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: handling null pointers/records to functions
Date: Sat, 21 Aug 2004 17:11:13 +0000 (UTC)
Date: 2004-08-21T17:11:13+00:00	[thread overview]
Message-ID: <cg7vnh$amj$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: Xns954C509814709jimmaureenrogers@127.0.0.1

Jim Rogers <jimmaureenrogers@worldnet.att.net> wrote:
:>quasar <quasar@nospam.com> wrote:
 
: You ask about returning some kind of null object. I suggest what 
: you might consider here is defining some value of the Data member
: to indicate no data. This approach avoids exception handling but
: is easier to get wrong at the calling context. The calling 
: context must compare all return values with the "no data" value
: before proceeding. Failure to do so will propogate bad data
: throughout the rest of the program.

Maybe you can also add a default value parameter to the function
that is returned when the Node_Ptr_Type value is null.

function Data_Part
   (Node_Ptr : Node_Ptr_Type; default_value: Data_Type) return Data_Type is
begin
    if node_ptr /= null then
        return Node_Ptr.Data;
    else
        Put_Line("Node passed to FUNCTION DATA_PART is null");
        return default_value;
    end if;
end Data_Part;

: The use of exceptions is really much more reliable in this case.

Have you, quasar, wanted a precondition of node_ptr /= null?
In this case the precondition will not be satisfied by a null
access. Therefore raising an exception seems an adequate solution.

-- Georg



  reply	other threads:[~2004-08-21 17:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-21 12:59 handling null pointers/records to functions quasar
2004-08-21 13:55 ` Jim Rogers
2004-08-21 17:11   ` Georg Bauhaus [this message]
2004-08-21 19:54 ` Jeffrey Carter
2004-08-22  4:12 ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox