ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Damir Shayhutdinov <damir@altlinux.org>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] вопрос по языку Си - порядок вычисления операндов
Date: Thu, 1 Oct 2009 09:00:32 +0400
Message-ID: <679044850909302200k506955ccmccf58200de2cb6bf@mail.gmail.com> (raw)
In-Reply-To: <20091001012428.GL10769@altlinux.org>

> Теперь посмотрим на вычитание указателей в строках 729-730.  Левый
> операнд вычитания может изменить ts->addedPackages.list, а правым
> операндом является сам ts->addedPackages.list.  Получается, что этот
> код зависит от порядка вычисления операндов -- а именно, может
> использоваться либо старое значение ts->addedPackages.list, либо
> уже новое значение.
>
> Воопрос соответствено насколько легален этот код, и вообще любая
> нетривиальная информация на эту тему.

Сделал тест:

#include <stdio.h>

static int change(int* p)
{
	*p = *p + 1;
	return *p;
}

void main(void)
{
	int a = 100;
	int b = change(&a) - a;
	printf("a=%d, b=%d\n", a, b);
}

После компиляции и запуска получается что b = 0; Что с -O0, что с -O2,
что с -O3.

Под рукой нет стандарта С, чтобы уточнить, но по крайней мере для gcc
этот код, похоже, легален.

  reply	other threads:[~2009-10-01  5:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-01  1:24 Alexey Tourbin
2009-10-01  5:00 ` Damir Shayhutdinov [this message]
2009-10-01  5:02 ` Kirill A. Shutemov
2009-10-01  5:09   ` Kirill A. Shutemov
2009-10-01  8:31 ` Kharitonov A. Dmitry
2009-10-01  8:36   ` Kharitonov A. Dmitry
2009-10-01  9:16   ` Kirill A. Shutemov
2009-10-01  9:47     ` Kharitonov A. Dmitry
2009-10-01  9:51       ` Kirill A. Shutemov
2009-10-01 10:10         ` Kharitonov A. Dmitry
2009-10-01 10:14           ` Damir Shayhutdinov
2009-10-01 10:32             ` Kharitonov A. Dmitry
2009-10-01  9:30   ` Led

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=679044850909302200k506955ccmccf58200de2cb6bf@mail.gmail.com \
    --to=damir@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