Differences between strings.h and string.h header files

Today, I use man string to view the method of using the string file (after all, the function name and the type of the incoming parameter and the play parameter in it, if it is not used for a period of time, it will be forgotten.)

Stumbled upon the description of strings.h in the string.h man page. This aroused my curiosity, very strange relationship between the strings and strings. I searched a few posts on the Internet, they are not clear enough, I will reorganize them today:

First, let's take a look at the contents of the man string:

It can be seen that some functions are included in the strings header file, but they do not appear in string.h. The environment as shown is macOS Sierra version number: 10.12.6

Including; index, rindex, strcasecmp, strncasecmp these four functions.

In order to find out, whether this header file only appears in Unix-like systems such as macos. I also checked in ubuntu system under linux.

We use the command, the man string command, and the same content is also visible. It can be seen that it is already a header file in the c standard library.

Advanced: Which header file should we use?

To clarify further, whether we are programming using strings or strings header files. Let's open the strings header file in the linux /usr/include folder to take a peek.

We are given a clear answer in the strings.h file:

The general idea is: If we use the string.h header file, then we don't need to include the strings.h file. Unless there is a situation. If the variable __USE_MISC is not defined, this variable will be defined in the strings.h header file. Because this variable is not defined in string.h. How to define it can be viewed in detail in the file /usr/include/strings.h.

Going a step further:

To further see what the community has to say about these two documents, we found a discussion on this topic on stackoverflow. Similar to our explanation:

View 1:

strings.h comes from the BSD branch in the unix evolution. Its content has been standardized by POSIX, but most of it is marked as legacy and can be easily replaced with other functions

View 2:

Typically <strings.h> just adds some useful but non-standard additional string functions to the standard header <string.h>. For maximum portability you should only use <string.h> but if you need the functions in <strings.h> more than you need portability then you can use <strings.h>instead of <string.h>.

 Specifically, whether this strings.h header file has been standardized, we still need to verify. But according to the performance of the two man pages. I think there's a 90% chance that it's already standardized. Because the man page of mac os has classified it as Standard C library. Strings and string.h are not just the difference of one more s .
 
End, welcome to leave a message for discussion. Welcome to reprint, please indicate the source when reprinting .
 
Reference link:
1. https://blog.csdn.net/xin_yu_xin/article/details/38672137
2. https://stackoverflow.com/questions/4291149/difference-between-string-h-and-strings-h
3. Linux man page 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324792279&siteId=291194637