What is valid std::strstr()'s signature?

Discussion in 'C++' started by Alex Vinokur, Oct 17, 2011.

  1. Alex Vinokur

    Alex Vinokur Guest

    Hi,

    What is valid std::strstr()'s signature?


    http://www.cplusplus.com/reference/clibrary/cstring/strstr/
    const char * strstr ( const char * str1, const char * str2 );
    char * strstr ( char * str1, const char * str2 );



    HP-UX B.11.23 U ia64
    /usr/include/string.h: extern char *strstr(const char *, const
    char *);


    Linux 2.6.18-238.1.1.el5
    /usr/include/string.h:extern char *strstr (__const char *__haystack,
    __const char *__needle)


    Thanks,

    Alex
     
    Alex Vinokur, Oct 17, 2011
    #1
    1. Advertisements

  2. Alex Vinokur

    Nobody Guest

    This (21.7p7):
    This is the ISO C definition:
    C doesn't have overloaded functions, so there can only be a single
    prototype. The strstr() function doesn't modify either string (hence the
    "const" on the argument types), but the return value (if not NULL) is a
    pointer into the target string specified by the first argument.

    If the target string can safely be modified, then it's safe to modify it
    via the returned pointer (hence no "const" on the return type). If the
    target string should not be modified, then it's not safe to modify it via
    the returned pointer either. The C++ definition uses overloading to encode
    these rules.
     
    Nobody, Oct 17, 2011
    #2
    1. Advertisements

  3. Alex Vinokur

    Alex Vinokur Guest

    Thanks.
    But where are C++-strstr()'s declared?
    string.h contains the only strstr() declaration.

    Alex
     
    Alex Vinokur, Oct 17, 2011
    #3
  4. In <cstdlib>. See Standard, [lib.c.strings]/10.

    V
     
    Victor Bazarov, Oct 17, 2011
    #4
  5. Alex Vinokur

    Marc Guest

    The two above are the correct ones.
    That's ancient, recent glibc has the correct declarations (and solaris
    has had them for a very long time).
     
    Marc, Oct 17, 2011
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.