Re: asciz_equal & asciz_length & strncmp
Bruno Haible <[email protected]>
| Newsgroups | gmane.lisp.clisp.devel |
|---|---|
| Message-ID | <2657067.A7eZZiSXY3@omega> |
Hi Sam,
> What's the status of these functions?
asciz_equal and asciz_length are the usual functions to use on C strings.
> Are they officially obsolete?
No.
> ISTR that strlen and strmp were avoided because they used registers that
> CLISP reserved for itself - it this still the case?
I avoided strlen and strcmp because
* As you say, we cannot expect that libc functions respect our choices
of reserved CPU registers. Thus the need to wrap calls of strlen and
strcmp between begin_system_call() / end_system_call().
* I also like the naming because "asciz" is just one data type among
many others, and we have a function named asciz_to_string. In other
words, the C and POSIX standards have terrible naming conventions.
(Could you tell me, without looking it up, what is the difference
between memcpy, mempcpy, and memccpy?)
> When can I use strncmp(3)? (we don't have a replacement)
strncmp is very easily used in the wrong way. (I guess I do it wrong
1 out of 2 times.) I prefer APIs that are maybe less general, but have
a semantics that is easier to grasp, such as
boolean asciz_startswith (const char* s, const char* prefix)
or
/* If s starts with the prefix, return the portion of s after the prefix,
otherwise return NULL. */
const char* asciz_tail (const char* s, const char* prefix)
Bruno
------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel