Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What is valid std::strstr()'s signature?

Reply
Thread Tools

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

 
 
Alex Vinokur
Guest
Posts: n/a
 
      10-17-2011
Hi,

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


http://www.cplusplus.com/reference/c...string/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
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      10-17-2011
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.

 
Reply With Quote
 
 
 
 
Alex Vinokur
Guest
Posts: n/a
 
      10-17-2011
On Oct 17, 2:52*pm, Nobody <(E-Mail Removed)> 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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      10-17-2011
On 10/17/2011 9:20 AM, Alex Vinokur wrote:
> On Oct 17, 2:52 pm, Nobody<(E-Mail Removed)> 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
 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      10-17-2011
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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not valid SSID name during setup using the wizard =?Utf-8?B?SE1WYWNhbmE=?= Wireless Networking 4 08-23-2005 05:38 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 3 04-27-2005 09:20 PM
Enigmail - no valid OpenPGP data found Chuck Firefox 0 04-26-2005 06:41 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
Valid file types Aschel Kritsos ASP .Net 1 11-14-2003 05:13 PM



Advertisments