From: David Abrahams (dave_at_[hidden])
Date: 2002-11-17 15:27:58
Thorsten Ottosen <nesotto_at_[hidden]> writes:
> I'll respond to all 3 messages by this.
> ----- Original Message -----
> From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
>> On Sun, 17 Nov 2002 18:22:20 +0100, Thorsten Ottosen
>> <nesotto_at_[hidden]> wrote:
>> >Yes, but note that having both is less fortunate. Either we agree that
>> >library writers check preconditions and then
>> >clients don't or we agree that clients check preconditions and library
>> >writers don't. One reason that C is such
>> >a pain in the *** to use is because its the cliets responsibility to
>> >conditions , e.g.
>> >int * i = malloc( sizeof( i ) );
>> >assert( i );
>> Well, apart from the C-style void*->int* conversion and the curious
>> sizeof(i) instead of sizeof(int), weren't you speaking of
>> preconditions? :-)
> Well, my point is that if you put the check in the library, then you
> do it once; if you don't put it there, then you do it n times. It
> does not matter what the check is.
But n can be 1 if you provide your own checked interface wrapper <wink>.
> On Sun, 17 Nov 2002 12:53:52 -0500, David Abrahams
> <dave_at_[hidden]> wrote:
>>Not all preconditions are effectively checkable
> then how should the client check them? I assume the client cannot
> check the preconditions any better than the library.
Right, but the client can ensure they're true via other means. For
example, if I write a function taking an A* parameter, how can I check
that the user hasn't passed something crazy, like
(A*)some_array_of_char? I can't. Clearly it is a precondition that the
A* parameter point to an A (or be NULL). However, the client has it
entirely within his power to avoid passing me bogus data.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk