Is there a particular reason for memmem being a GNU extension?

后端 未结 1 1452
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 07:06

In C, the memmem function is used to locate a particular sequence of bytes in a memory area. It can be assimilated to strstr, which is dedicated t

1条回答
  •  孤街浪徒
    2021-01-02 07:34

    Historically, that is before the first revision of the Standard, C has been made by compiler writers.

    In the case of strstr, it is a little bit different because it has been introduced by the C Committee, the C89 Rationale document tells us that:

    "The strstr function is an invention of the Committee. It is included as a hook for efficient algorithms, or for built-in substring instruction."

    The C Committee does not explain why it has not made a more general function not limited to strings so any reasoning may only be speculation. My only guess is the use case has been considered not important enough to have a generic memmem instead of strstr. Remember that in the goals of C there is this requirement (in the C99 Rationale) "Keep the language small and simple". Also even POSIX didn't consider it for inclusion.

    In any case to my knowledge nobody has proposed any Defect Report or proposal to have memmem included.

    0 讨论(0)
提交回复
热议问题