Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10919 > unrolled thread

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

Started byAlex Vinokur <alex.vinokur@gmail.com>
First post2011-10-17 03:50 -0700
Last post2011-10-17 16:23 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.lang.c++


Contents

  What is valid std::strstr()'s signature? Alex Vinokur <alex.vinokur@gmail.com> - 2011-10-17 03:50 -0700
    Re: What is valid std::strstr()'s signature? Nobody <nobody@nowhere.com> - 2011-10-17 13:52 +0100
      Re: What is valid std::strstr()'s signature? Alex Vinokur <alex.vinokur@gmail.com> - 2011-10-17 06:20 -0700
        Re: What is valid std::strstr()'s signature? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-17 10:34 -0400
          Re: What is valid std::strstr()'s signature? Leigh Johnston <leigh@i42.co.uk> - 2011-10-17 15:39 +0100
    Re: What is valid std::strstr()'s signature? Marc <marc.glisse@gmail.com> - 2011-10-17 16:23 +0000

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

FromAlex Vinokur <alex.vinokur@gmail.com>
Date2011-10-17 03:50 -0700
SubjectWhat is valid std::strstr()'s signature?
Message-ID<cde857e0-4f39-4a8e-9095-78cf74530a92@w5g2000yqw.googlegroups.com>
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

[toc] | [next] | [standalone]


#10921

FromNobody <nobody@nowhere.com>
Date2011-10-17 13:52 +0100
Message-ID<pan.2011.10.17.12.52.54.970000@nowhere.com>
In reply to#10919
On Mon, 17 Oct 2011 03:50:59 -0700, Alex Vinokur wrote:

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

This (21.7p7):

> 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:

This is the ISO C definition:

> extern char *strstr(const char *, const char *);

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.

[toc] | [prev] | [next] | [standalone]


#10922

FromAlex Vinokur <alex.vinokur@gmail.com>
Date2011-10-17 06:20 -0700
Message-ID<4719d2e5-f7f0-4539-8dfb-9554d36ee9a3@w1g2000yqm.googlegroups.com>
In reply to#10921
On Oct 17, 2:52 pm, Nobody <nob...@nowhere.com> wrote:
> On Mon, 17 Oct 2011 03:50:59 -0700, Alex Vinokur wrote:
> > What is valid std::strstr()'s signature?
>
> This (21.7p7):
>
> > 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:
>
> This is the ISO C definition:
>
> > extern char *strstr(const char *, const char *);
>
> 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.

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

Alex

[toc] | [prev] | [next] | [standalone]


#10923

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-10-17 10:34 -0400
Message-ID<j7hecp$o87$1@dont-email.me>
In reply to#10922
On 10/17/2011 9:20 AM, Alex Vinokur wrote:
> On Oct 17, 2:52 pm, Nobody<nob...@nowhere.com>  wrote:
>> On Mon, 17 Oct 2011 03:50:59 -0700, Alex Vinokur wrote:
>>> What is valid std::strstr()'s signature?
>>
>> This (21.7p7):
>>
>>> 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:
>>
>> This is the ISO C definition:
>>
>>> extern char *strstr(const char *, const char *);
>>
>> 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.
>
> Thanks.
> But where are C++-strstr()'s declared?
> string.h contains the only strstr() declaration.

In <cstdlib>.  See Standard, [lib.c.strings]/10.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#10924

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-10-17 15:39 +0100
Message-ID<CK6dnXFQo_-4owHTnZ2dnUVZ8qWdnZ2d@giganews.com>
In reply to#10923
On 17/10/2011 15:34, Victor Bazarov wrote:
> On 10/17/2011 9:20 AM, Alex Vinokur wrote:
>> On Oct 17, 2:52 pm, Nobody<nob...@nowhere.com> wrote:
>>> On Mon, 17 Oct 2011 03:50:59 -0700, Alex Vinokur wrote:
>>>> What is valid std::strstr()'s signature?
>>>
>>> This (21.7p7):
>>>
>>>> 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:
>>>
>>> This is the ISO C definition:
>>>
>>>> extern char *strstr(const char *, const char *);
>>>
>>> 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.
>>
>> Thanks.
>> But where are C++-strstr()'s declared?
>> string.h contains the only strstr() declaration.
>
> In <cstdlib>. See Standard, [lib.c.strings]/10.

strstr is <cstring> not <cstdlib>

/Leigh

[toc] | [prev] | [next] | [standalone]


#10928

FromMarc <marc.glisse@gmail.com>
Date2011-10-17 16:23 +0000
Message-ID<j7hkq6$odl$1@news-rocq.inria.fr>
In reply to#10919
Alex Vinokur  wrote:

> What is valid std::strstr()'s signature?
> const char * strstr ( const char * str1, const char * str2 );
>       char * strstr (       char * str1, const char * str2 );

The two above are the correct ones.

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

That's ancient, recent glibc has the correct declarations (and solaris
has had them for a very long time).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web