Re: How is strlen implemented?
- From: Chris Torek <nospam@xxxxxxxxx>
- Date: 23 Apr 2005 18:07:21 GMT
>Chris Torek wrote:
>>There are functions that work on "non-stringy arrays"; in particular,
>>the mem* functions ... If you have an array that always contains
>>exactly 40 characters, and it is possible that none of them is '\0'
>>but you want to find out whether there is a '\0' in those 40
>>characters, you can use memchr() ...
In article <1114276994.583523.162370@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Minti <imanpreet@xxxxxxxxx> wrote:
>Pardon me Chris, but I really don't get the drift of what you are
>trying to convey. These strings are also "stringy", I don't see how
>these are "non-stringy".
If there is no '\0' byte in all 40 characters, it is not a string.
If there is a '\0' byte somewhere within those 40 characters, it
*is* a string -- and any characters after the first such '\0' are
not part of the string (but remain part of the array).
>IOW you are assuming that these "non-stringy" arrays are also supposed
>to end with a null character. "Stringy" I say.
In other words, I am saying that these arrays do not contain strings
if and only if they do not contain a '\0'. Note that strncpy()
sometimes makes such arrays (which is one reason some people invented
strlcpy()).
If I may draw an analogy: in mathematics, a statement is false if
there is even a single counterexample. Hence "x * (1/x) = 1" is
a false statement mathematically, because it does not hold for x=0.
(But note that if we limit it, "x * (1/x) = 1 provided x \ne 0",
the statement becomes true for x \elem real, while it remains false
for x \elem integer, and so on.) (Note that details like "x is a
real number" also matter in computing, where float and double do
not really give us "real numbers", but rather approximations.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
.
- References:
- How is strlen implemented?
- From: roy
- Re: How is strlen implemented?
- From: Chris Torek
- Re: How is strlen implemented?
- From: Minti
- How is strlen implemented?
- Prev by Date: Re: How is strlen implemented?
- Next by Date: How do I check if a file is empty in C??
- Previous by thread: Re: How is strlen implemented?
- Next by thread: Re: How is strlen implemented?
- Index(es):
Relevant Pages
|