ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Vladimir Didenko <vladimir.didenko@gmail.com>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] memcpy глючит (или я не умею его готовить)
Date: Fri, 22 Feb 2019 23:51:20 +0300
Message-ID: <CAHRK1yPVYsTY3+ZEXrSyG5nL6=MpVcjxF68B4YQQTVkBbLRNSQ@mail.gmail.com> (raw)
In-Reply-To: <42f17a50-affe-4c54-99ad-88502a65854f@gmail.com>

пт, 22 февр. 2019 г. в 22:29, Leonid Krivoshein:
> 21.02.2019 16:25, Alexey V. Vissarionov пишет:
> > (_data.size % 2) лично я поменял бы на (_data.size & 0x01)
>
> Да, так на порядок быстрее.

Это одинаково. Не надо оптимизировать за компилятор, он с этим и сам
неплохо справляется (иногда, даже чересчур)

>
> Тут ко всему не очевидное поведение компилятора при работе с адресами,
> когда их складывают с целыми (много от чего зависит и в ряде случаев
> просто на ворнинги можно нарваться). Такой код в любом случае сразу
> переписывать на более безопасный, независимо от memcpy()/memmove().
> Например, так:
>
> memmove(&_data.data[8], &data.data[9], _data.size - 9); /* если тип
> данных [unsigned] char */
>

Вы глупость написали. Арифметика указателей и целых чисел вполне
определена и безопасна, если не выходить за границы массива. И еще -
запись p + 8 и &p[8] равносильны согласно стандарту языка C.


-- 
С уважением,
Владимир.

  reply	other threads:[~2019-02-22 20:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 13:17 Paul Wolneykien
2019-02-21 13:22 ` Vladimir Didenko
2019-02-21 13:28   ` Paul Wolneykien
2019-02-21 13:25 ` Alexey V. Vissarionov
2019-02-22 19:27   ` Leonid Krivoshein
2019-02-22 20:51     ` Vladimir Didenko [this message]
2019-02-22 22:48       ` Leonid Krivoshein
2019-02-23  1:21         ` Mikhail Efremov
2019-02-23 12:28           ` Leonid Krivoshein
2019-02-23 12:55             ` Alexey V. Vissarionov
2019-02-23 13:08               ` Leonid Krivoshein
2019-02-23 14:46                 ` Alexey Tourbin
2019-02-23 15:02                   ` Leonid Krivoshein
2019-02-24 11:06               ` Mikhail Efremov
2019-02-24 16:22                 ` [devel] gcc pointer arithmetics 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='CAHRK1yPVYsTY3+ZEXrSyG5nL6=MpVcjxF68B4YQQTVkBbLRNSQ@mail.gmail.com' \
    --to=vladimir.didenko@gmail.com \
    --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