Re: Should function argument be changed in function body?
- From: "Mark" <sober@xxxxxxxxxxxx>
- Date: Wed, 27 Jul 2005 21:32:34 GMT
"Chris Croughton" <chris@xxxxxxxxxxxx> wrote in message
news:slrndedgdu.pfn.chris@xxxxxxxxxxxxxxxxxxxxx
> On Tue, 26 Jul 2005 20:35:56 GMT, Mark
> <sober@xxxxxxxxxxxx> wrote:
>
>> "CBFalconer" <cbfalconer@xxxxxxxxx> wrote in message
>> news:42E595E5.B2D21E58@xxxxxxxxxxxx
>> <snip>
>>> Of course, after all the fuss, this is a function that can be
>>> improved by not altering the input parameter.
>> And by improved, do you mean broken?
>>
>>> size_t length_of_string(const char *s) {
>>> const char *t = s;
>>>
>>> while (*t++) continue;
>>> return t - s;
>>> }
>>>
>>> (and I will live with the possibility that ptr_diff is too small)
>>
>> You're also living with the fact that:
>> printf("%d\n", length_of_string(""));
>> will print 1.
>
> Actually, it will exhibit undefined behaviour since the function returns
> size_t and %d expects an int...
Actually, it's very well defined on my implementation.
size_t = unsigned int
with value explicitly set to 1 the sign bit is irrelevant.
You've peaked my curiosity, on what implementations
(excluding the infamous DeathStation 9000) is a
size_t not defined as an 'unsigned int' ?
> Since we're being picky, and all...
We? Ah, I didn't realize there were two of you! :-)
Regards,
Mark
.
- Follow-Ups:
- Re: Should function argument be changed in function body?
- From: Chris Croughton
- Re: Should function argument be changed in function body?
- References:
- Should function argument be changed in function body?
- From: Morgan Cheng
- Re: Should function argument be changed in function body?
- From: Tim Rentsch
- Re: Should function argument be changed in function body?
- From: CBFalconer
- Re: Should function argument be changed in function body?
- From: Tim Rentsch
- Re: Should function argument be changed in function body?
- From: Steve Summit
- Re: Should function argument be changed in function body?
- From: Tim Rentsch
- Re: Should function argument be changed in function body?
- From: Chris Croughton
- Re: Should function argument be changed in function body?
- From: CBFalconer
- Re: Should function argument be changed in function body?
- From: Mark
- Re: Should function argument be changed in function body?
- From: Chris Croughton
- Should function argument be changed in function body?
- Prev by Date: Re: Question on arrays within a struct and sprintf
- Next by Date: Re: strange pointer behavior
- Previous by thread: Re: Should function argument be changed in function body?
- Next by thread: Re: Should function argument be changed in function body?
- Index(es):
Relevant Pages
|
|