ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] str*(3) - C vs. C++
  @ 2009-06-14 23:31 ` Alexey I. Froloff
  2009-06-14 23:44   ` Led
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alexey I. Froloff @ 2009-06-14 23:31 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

On Tue, Jun 09, 2009 at 02:37:06AM +0400, QA Team Robot wrote:
> backends/midi/alsa.cpp:234: error: invalid conversion from 'const char*' to 'char*'
backends/midi/alsa.cpp:234: if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)

Где arg имеет тип const char *.

SYNOPSIS
       #include <string.h>

       char *strpbrk(const char *s, const char *accept);
                     ^^^^^^^^^^^^^

/usr/include/c++/4.4.0/cstring:  strpbrk(char* __s1, const char* __s2)
                                         ^^^^^^^^^^
/usr/include/c++/4.4.0/cstring:  { return __builtin_strpbrk(const_cast<const char*>(__s1), __s2); }
                                                            ^^^^^^^^^^^^^^^^^^^^^^^

И как это называется?  Аналогично strchr(3) и др.

-- 
Regards,
Sir Raorn.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-14 23:31 ` [devel] str*(3) - C vs. C++ Alexey I. Froloff
@ 2009-06-14 23:44   ` Led
  2009-06-15  5:45   ` Ivan A. Melnikov
  2009-06-15  7:40   ` Alexey Rusakov
  2 siblings, 0 replies; 8+ messages in thread
From: Led @ 2009-06-14 23:44 UTC (permalink / raw)
  To: ALT Linux Team development discussions

On Monday, 15 June 2009 02:31:29 Alexey I. Froloff wrote:
> On Tue, Jun 09, 2009 at 02:37:06AM +0400, QA Team Robot wrote:
> > backends/midi/alsa.cpp:234: error: invalid conversion from 'const char*'
> > to 'char*'
>
> backends/midi/alsa.cpp:234: if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
>
> Где arg имеет тип const char *.
>
> SYNOPSIS
>        #include <string.h>
>
>        char *strpbrk(const char *s, const char *accept);
>                      ^^^^^^^^^^^^^
>
> /usr/include/c++/4.4.0/cstring:  strpbrk(char* __s1, const char* __s2)
>                                          ^^^^^^^^^^
> /usr/include/c++/4.4.0/cstring:  { return
> __builtin_strpbrk(const_cast<const char*>(__s1), __s2); }
> ^^^^^^^^^^^^^^^^^^^^^^^
>
> И как это называется?  Аналогично strchr(3) и др.

inline char*
  strpbrk(char* __s1, const char* __s2)

Вы упустили "inline". С "inline" ИМХО всё не настолько критично:)

-- 
Led


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-14 23:31 ` [devel] str*(3) - C vs. C++ Alexey I. Froloff
  2009-06-14 23:44   ` Led
@ 2009-06-15  5:45   ` Ivan A. Melnikov
  2009-06-15 13:04     ` Alexey I. Froloff
  2009-06-15  7:40   ` Alexey Rusakov
  2 siblings, 1 reply; 8+ messages in thread
From: Ivan A. Melnikov @ 2009-06-15  5:45 UTC (permalink / raw)
  To: devel

On Mon, 15 Jun 2009 03:31:29 +0400
"Alexey I. Froloff" <raorn@altlinux.org> wrote:

> On Tue, Jun 09, 2009 at 02:37:06AM +0400, QA Team Robot wrote:
> > backends/midi/alsa.cpp:234: error: invalid conversion from 'const
> > char*' to 'char*'
> backends/midi/alsa.cpp:234: if ((p = strpbrk(arg, ADDR_DELIM)) ==
> NULL)
> 
> Где arg имеет тип const char *.
> 
> SYNOPSIS
>        #include <string.h>
> 
>        char *strpbrk(const char *s, const char *accept);
>                      ^^^^^^^^^^^^^
> 
> /usr/include/c++/4.4.0/cstring:  strpbrk(char* __s1, const char* __s2)
>                                          ^^^^^^^^^^
> /usr/include/c++/4.4.0/cstring:  { return
> __builtin_strpbrk(const_cast<const char*>(__s1), __s2); }
> ^^^^^^^^^^^^^^^^^^^^^^^
> 
> И как это называется?  Аналогично strchr(3) и др.
> 


Использую libstdc++4.4-devel-4.4.0-alt3. Здесь эти определения
присутствуют только если не определен символ препроцессора
__CORRECT_ISO_CPP_STRING_H_PROTO, который, вроде бы, должен
определяться в <string.h> из glibc-devel-2.10.1-alt2 на 37-ой
строке. Я успешно скомпилировал такое вот:

$ cat a.cpp 

#include <cstring>

const char* test = "Test";
const char* accept = "s";

int main()
{
    return std::strpbrk(test, accept) - test;
}

Полученный бинарник действительно возвращает код 2.

Может, у Вас какой-то string.h подсоввывается неправильный? Что за
пакет?

-- 
WBR,
Ivan A. Melnikov



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-14 23:31 ` [devel] str*(3) - C vs. C++ Alexey I. Froloff
  2009-06-14 23:44   ` Led
  2009-06-15  5:45   ` Ivan A. Melnikov
@ 2009-06-15  7:40   ` Alexey Rusakov
  2 siblings, 0 replies; 8+ messages in thread
From: Alexey Rusakov @ 2009-06-15  7:40 UTC (permalink / raw)
  To: ALT Linux Team development discussions

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

В Пнд, 15/06/2009 в 03:31 +0400, Alexey I. Froloff пишет:
> On Tue, Jun 09, 2009 at 02:37:06AM +0400, QA Team Robot wrote:
> > backends/midi/alsa.cpp:234: error: invalid conversion from 'const char*' to 'char*'
> backends/midi/alsa.cpp:234: if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
> 
> Где arg имеет тип const char *.
> 
> SYNOPSIS
>        #include <string.h>
> 
>        char *strpbrk(const char *s, const char *accept);
>                      ^^^^^^^^^^^^^
> 
> /usr/include/c++/4.4.0/cstring:  strpbrk(char* __s1, const char* __s2)
>                                          ^^^^^^^^^^
> /usr/include/c++/4.4.0/cstring:  { return __builtin_strpbrk(const_cast<const char*>(__s1), __s2); }
>                                                             ^^^^^^^^^^^^^^^^^^^^^^^
> 
> И как это называется?  Аналогично strchr(3) и др.
В cstring:45 находится #include <string.h>, а в string.h:294
определяется вполне себе "правильный" const-aware strpbrk(). Ну и да,
как тут рядом заметили, внимательно смотрим на ifndef в cstring:99

-- 
  Alexey "Ktirf" Rusakov
  GNOME Project
  ALT Linux Team

[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-15  5:45   ` Ivan A. Melnikov
@ 2009-06-15 13:04     ` Alexey I. Froloff
  2009-06-15 13:13       ` Damir Shayhutdinov
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-06-15 13:04 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

On Mon, Jun 15, 2009 at 09:45:47AM +0400, Ivan A. Melnikov wrote:
> Я успешно скомпилировал такое вот:
> $ cat a.cpp 
Вот это уже не компилится:

$ cat t.cpp
#include <cstring>

const char* test = "Test";
const char* accept = "s";

char *foo(const char *s, const char *a)
{
        return std::strpbrk(s, a);
}

int main()
{
    return foo(test, accept) - test;
}
$ g++ -Wall -o tt t.cpp
t.cpp: In function 'char* foo(const char*, const char*)':
t.cpp:8: error: invalid conversion from 'const char*' to 'char*'
[1]    12884 exit 1     g++ -Wall -o tt t.cpp

-- 
Regards,
Sir Raorn.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-15 13:04     ` Alexey I. Froloff
@ 2009-06-15 13:13       ` Damir Shayhutdinov
  2009-06-15 13:51         ` Alexey I. Froloff
  0 siblings, 1 reply; 8+ messages in thread
From: Damir Shayhutdinov @ 2009-06-15 13:13 UTC (permalink / raw)
  To: ALT Linux Team development discussions

> char *foo(const char *s, const char *a)
тут должно быть const char* foo
По идее strpbrk возвращает указатель на часть строки, поэтому если
передается строка const char*, то и результат должен быть const char*,
иначе возможно получить неconst-указатель на часть const-строки.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-15 13:13       ` Damir Shayhutdinov
@ 2009-06-15 13:51         ` Alexey I. Froloff
  2009-06-15 15:49           ` Alexey Tourbin
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey I. Froloff @ 2009-06-15 13:51 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 219 bytes --]

On Mon, Jun 15, 2009 at 05:13:55PM +0400, Damir Shayhutdinov wrote:
> > char *foo(const char *s, const char *a)
> тут должно быть const char* foo
О мой мозг.  Как жеж я "люблю" Си+плюс.

-- 
Regards,
Sir Raorn.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [devel] str*(3) - C vs. C++
  2009-06-15 13:51         ` Alexey I. Froloff
@ 2009-06-15 15:49           ` Alexey Tourbin
  0 siblings, 0 replies; 8+ messages in thread
From: Alexey Tourbin @ 2009-06-15 15:49 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 698 bytes --]

On Mon, Jun 15, 2009 at 05:51:21PM +0400, Alexey I. Froloff wrote:
> On Mon, Jun 15, 2009 at 05:13:55PM +0400, Damir Shayhutdinov wrote:
> > > char *foo(const char *s, const char *a)
> > тут должно быть const char* foo
> О мой мозг.  Как жеж я "люблю" Си+плюс.

В си+плюсе функции могут быть перегружены: если аргумент константный,
то и значение константное; а второй прототип соответственно без const
то и другое.  Когда людишки функцию вызывают, то си+плюс смотрит, какой
прототип надо выбрать.

Это написано в книжке "Страус" на странице 666.

Соответственно в string.h у функций типа strchr два прототипа:
char *strchr(char *s, int c);
const char *strchr(const char *s, int c);

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-06-15 15:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-14 23:31 ` [devel] str*(3) - C vs. C++ Alexey I. Froloff
2009-06-14 23:44   ` Led
2009-06-15  5:45   ` Ivan A. Melnikov
2009-06-15 13:04     ` Alexey I. Froloff
2009-06-15 13:13       ` Damir Shayhutdinov
2009-06-15 13:51         ` Alexey I. Froloff
2009-06-15 15:49           ` Alexey Tourbin
2009-06-15  7:40   ` Alexey Rusakov

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git