ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Ivan Zakharyaschev <imz@altlinux.org>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] [SCM] packages/apt: heads/rework-dynamic-mmap
Date: Tue, 11 Feb 2020 20:05:38 +0300 (MSK)
Message-ID: <alpine.LFD.2.20.2002112004250.6363@imap.altlinux.org> (raw)
In-Reply-To: <alpine.LFD.2.20.2002111722580.6363@imap.altlinux.org>

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

On Tue, 11 Feb 2020, Ivan Zakharyaschev wrote:

> On Tue, 11 Feb 2020, Dmitry V. Levin wrote:
> 
> > On Tue, Feb 11, 2020 at 04:47:41PM +0300, Ivan Zakharyaschev wrote:
> > [...]
> > > commit e785f0e8636e47a672445e70f2923a5eea566b33
> > > Author: Ivan Zakharyaschev <imz@altlinux.org>
> > > Date:   Wed Jan 29 04:41:13 2020 +0300
> > > 
> > >     use the safer C++-style static_cast instead of a C-style cast (from void*)
> > >     
> > >     What is happening here:
> > >     
> > >     Map->RawAllocate() returns the index in an array of bytes (i.e., of char;
> > >     no matter whether they are (un)signed); therefore, we cast the base
> > >     pointer to the corresponding type, so that the pointer arithmetic
> > >     gives a pointer to the beginning of the allocated space.
> > >     
> > >     We do not want to rely on non-standard void*-arithmetic.
> > 
> > We - это кто, и почему они не хотят полагаться на то, что работает?
> 
> Да это расширение gcc, которое работает , когда язык C, а когда C++ -- 
> запрещено и в gcc. (Я вроде пробовал, и gcc запретил, когда мы в прошлый 
> раз обсуждали падение apt-а на e2k.)

-bash-4.3$ cat charp-arith.cxx
#include <stddef.h>
#include <stdio.h>

char buf[] = "foo";

int main(const int argc, char ** const argv)
{
  char * const begin = &buf[0];
  char * const end = &buf[2];
  const ptrdiff_t diff = end - begin;
  printf("%td\n", diff);
}
-bash-4.3$ gcc -Wall -xc charp-arith.cxx && ./a.out; echo $?
2
0
-bash-4.3$ gcc -Wall charp-arith.cxx && ./a.out; echo $?
2
0
-bash-4.3$ gcc -Wall -std=gnu++17 charp-arith.cxx && ./a.out; echo $?
2
0
-bash-4.3$ diff charp-arith.cxx voidp-arith.cxx
8,9c8,9
<   char * const begin = &buf[0];
<   char * const end = &buf[2];
---
>   void * const begin = &buf[0];
>   void * const end = &buf[2];
-bash-4.3$ gcc -Wall -xc voidp-arith.cxx && ./a.out; echo $?
2
0
-bash-4.3$ gcc -Wall voidp-arith.cxx && ./a.out; echo $?
voidp-arith.cxx: In function ‘int main(int, char**)’:
voidp-arith.cxx:10:32: error: invalid use of ‘void’
   10 |   const ptrdiff_t diff = end - begin;
      |                                ^~~~~
1
-bash-4.3$ gcc -Wall -std=gnu++17 voidp-arith.cxx && ./a.out; echo $?
voidp-arith.cxx: In function ‘int main(int, char**)’:
voidp-arith.cxx:10:32: error: invalid use of ‘void’
   10 |   const ptrdiff_t diff = end - begin;
      |                                ^~~~~
1
-bash-4.3$ gcc -Wall -std=gnu++2a voidp-arith.cxx && ./a.out; echo $?
voidp-arith.cxx: In function ‘int main(int, char**)’:
voidp-arith.cxx:10:32: error: invalid use of ‘void’
   10 |   const ptrdiff_t diff = end - begin;
      |                                ^~~~~
1
-bash-4.3$ 


-- 
Best regards,
Ivan

  reply	other threads:[~2020-02-11 17:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 16:24   ` Ivan Zakharyaschev
2020-01-29 16:32     ` Ivan Zakharyaschev
2020-01-30  9:30       ` Aleksei Nikiforov
2020-01-30  8:56     ` Aleksei Nikiforov
2020-02-11 13:47       ` Ivan Zakharyaschev
2020-02-11 13:51         ` [devel] std::optional; was: " Ivan Zakharyaschev
2020-02-11 20:06           ` [devel] std::optional Dmitry V. Levin
2020-02-11 14:00         ` [devel] [SCM] packages/apt: heads/rework-dynamic-mmap Dmitry V. Levin
2020-02-11 14:24           ` Ivan Zakharyaschev
2020-02-11 17:05             ` Ivan Zakharyaschev [this message]
2020-02-11 18:14               ` Dmitry V. Levin
2020-02-12  2:14                 ` Ivan Zakharyaschev
2020-02-12  8:47                   ` Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.20.2002112004250.6363@imap.altlinux.org \
    --to=imz@altlinux.org \
    --cc=devel@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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