Re: signed vs unsigned
* roberts.noah@gm ail.com:[color=blue]
> Alf P. Steinbach wrote:[color=green]
>> * Neil Cerutti:[color=darkred]
>>> On 2006-02-21, Tomás <NULL@NULL.NULL > wrote:
>>>> My first rule is to write "const" wherever I can.
>>>> (except for return types).
>>>>
>>>> My second rule is to write "unsigned" wherever I can.
>>> I don't agree with that rule.
>>>
>>>> Thus I'll write:
>>>>
>>>> unsigned GetDogAge(unsig ned const age)
>>>> {
>>>> return age * 7;
>>>> }
>>> What do you expect to happen if a client passes in an negative int?
>>>
>>> The argument is not in the domain, yet the error has been rendered
>>> impossible to detect or recover from.[/color]
>> I don't disagree with your viewpoint regarding using or not using
>> unsigned whenever possible; I think both are valid viewpoints, and as
>> with indentation the main thing is to be consistent in one's choices.
>>
>> However, I disagree with your reason!
>>
>> With the unsigned argument a validity test might go like
>>
>> assert( age < 200 ); // unsigned validity test.
>>
>> With a signed argument the test might go like
>>
>> assert( age >= 0 ); // signed validity test.
>> assert( age < 200 ); // more signed validity test.
>>
>> Now, first of all that demonstrates the "impossible to detect" is simply
>> incorrect, and second, in my view it demonstrates a slight superiority
>> for unsigned in this particular case, with respect to validity testing.[/color]
>
> I believe he is talking about something like this:
>[/color]
[snip][color=blue]
> int t = -5;
> unsigned int x = GetDogAge(t);[/color]
Yes, that would be caught by the validity test for unsigned formal arg,
assert( age < 200 );
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
* roberts.noah@gm ail.com:[color=blue]
> Alf P. Steinbach wrote:[color=green]
>> * Neil Cerutti:[color=darkred]
>>> On 2006-02-21, Tomás <NULL@NULL.NULL > wrote:
>>>> My first rule is to write "const" wherever I can.
>>>> (except for return types).
>>>>
>>>> My second rule is to write "unsigned" wherever I can.
>>> I don't agree with that rule.
>>>
>>>> Thus I'll write:
>>>>
>>>> unsigned GetDogAge(unsig ned const age)
>>>> {
>>>> return age * 7;
>>>> }
>>> What do you expect to happen if a client passes in an negative int?
>>>
>>> The argument is not in the domain, yet the error has been rendered
>>> impossible to detect or recover from.[/color]
>> I don't disagree with your viewpoint regarding using or not using
>> unsigned whenever possible; I think both are valid viewpoints, and as
>> with indentation the main thing is to be consistent in one's choices.
>>
>> However, I disagree with your reason!
>>
>> With the unsigned argument a validity test might go like
>>
>> assert( age < 200 ); // unsigned validity test.
>>
>> With a signed argument the test might go like
>>
>> assert( age >= 0 ); // signed validity test.
>> assert( age < 200 ); // more signed validity test.
>>
>> Now, first of all that demonstrates the "impossible to detect" is simply
>> incorrect, and second, in my view it demonstrates a slight superiority
>> for unsigned in this particular case, with respect to validity testing.[/color]
>
> I believe he is talking about something like this:
>[/color]
[snip][color=blue]
> int t = -5;
> unsigned int x = GetDogAge(t);[/color]
Yes, that would be caught by the validity test for unsigned formal arg,
assert( age < 200 );
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Comment