On Mon, 19 Dec 2005 19:26:13 +0000, Mike Amling wrote:
> Bodo Moeller wrote:
>>
>> Yes, strlen(buffer) is correct. If you write 'buffer' where 'buffer'
>> has been declared as an array, the value of this expression magically
>> becomes a pointer to the first element of that array, which is exactly
>> what strlen() expects.
>>
>> It's strlen(&buffer) that would be incorrect: In connection with the
>> '&' operator, the C magic does not apply, and '&buffer' is a pointer
>> to an *array*, which is *not* what strlen() expects according to its
>> prototype.
>
> Yes. strlen(&buffer[0]) would also be correct.
>
> --Mike Amling
Thanks, I've already implemented such a thing:
#define SIZEOF(buf) (sizeof(buf)/sizeof(buf[0]))
I think it doesn't have any side effects...
The reason was that strlen() didn't work right, of course, if the buffer
didn't have a trailing zero or had a zero somewhere else. I've already
tested my new implementation with test vectors and it's OK. Will post
it in the next message. Thanks!
Received on Fri Dec 23 20:11:07 2005