Boost logo

Boost :

From: Chris Cleeland (cleeland_at_[hidden])
Date: 2006-01-06 12:54:01


On Fri, 6 Jan 2006, Peter Dimov wrote:

> Chris Cleeland wrote:
> > Whatever is necessary. If the args were shorts (signed or
> > unsigned), the interface is representing that the following would be
> > legal:
> >
> > asio::ipv4::address my_address(322, 798, 0, 1024);
> >
> > And we know that's not correct.
>
> If the arguments are unsigned chars, you (the author of the function) have
> no way of knowing whether it's correct, because you won't see 322 or 798.

I'm missing the point of what you're saying. If the args are unsigned chars,
there is no need for the author of the function to check the range b/c the
range is implicit in the type. Hopefully pedantic compilers will issue
warnings regarding loss of precision via implicit conversion catching errors
like this at compile time rather than at execution time.

If, otoh, the args are *shorts*, though, then there becomes a need to check
validity at execution time.

> > If the caller trusts implicit conversions rather than explicitly passing
> > unsigned chars, then that's their problem.
>
> Callers that explicitly pass unsigned char don't care about the argument
> type; their code will work with either.

Of course they will.

I can't tell: are you arguing that the interface should use unsigned short or
unsigned char?

-- 
  Chris Cleeland, cleeland_c @ ociweb.com, http://www.milodesigns.com/~chris
     Principal Software Engineer, Object Computing, Inc., +1 314 579 0066
      Support Me Supporting Cancer Survivors in Ride for the Roses 2005
    >>>>>>>>>    Donate at http://www.milodesigns.com/donate    <<<<<<<<<

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk