From: Alexey Rusakov <ktirf@altlinux.org>
To: ALT Linux Sisyphus discussions <sisyphus@lists.altlinux.org>
Cc: Serge Ryabchun <sr@osdn.org.ua>
Subject: Re: [sisyphus] Странности при переходе объединении двух целых в вещественное на x86_64
Date: Fri, 07 Aug 2009 17:15:47 +0400
Message-ID: <1249650948.8229.39.camel@latitude.localdomain> (raw)
In-Reply-To: <c803b7870908070559rde88499j55985ef63b484f78@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3148 bytes --]
В Птн, 07/08/2009 в 15:59 +0300, Serge Ryabchun пишет:
> Это не повод собирать не верный код:
>
> [sr@sr 6]$ gcc-4.3 -Wall -O2 f2.c
> f2.c: In function 'main':
> f2.c:10: warning: dereferencing type-punned pointer will break
> strict-aliasing rules
> [sr@sr 6]$ ./a.out
> TEST 00: 0.000000
> [sr@sr 6]$
> [sr@sr 6]$ gcc-4.4 -Wall -O2 f2.c
> f2.c: In function 'main':
> f2.c:10: warning: dereferencing type-punned pointer will break
> strict-aliasing rules
> [sr@sr 6]$ ./a.out
> TEST 00: 3.140000
По-моему, это вопрос из разряда разрешённости к использованию
конструкции reinterpret_cast<> в С++. Некоторые пользуются. На некоторых
архитектурах и в некоторых условиях результат даже работает. В данном
случае не повезло. Это C, в нём можно почти всё, в том числе и
непринуждённым движением прострелить себе ногу.
> 2009/8/7 Alexey Rusakov <ktirf@altlinux.org>:
> > В Птн, 07/08/2009 в 12:02 +0300, Roman Savochenko пишет:
> >> Kirill A. Shutemov wrote:
> >> > 2009/8/7 Roman Savochenko <rom_as@diyaorg.dp.ua>:
> >> >
> >> >> Kirill A. Shutemov wrote:
> >> >>
> >> >>>>> И во всех трёх вариантах нарушили strict aliasing. Используйте union.
> >> >>>>>
> >> >>>> ним работает, но это не решение, поскольку приведенные мною обороты
> >> >>>> распространены и я не уверен что подобных проблем нет в других частях
> >> >>>> моей,
> >> >>>> в общем-то не маленькой, программы.
> >> >>>>
> >> >>>>
> >> >>> Есть повод исправить код.
> >> >>>
> >> >>>
> >> >> Я не считаю его ошибочным.
> >> >>
> >> > Strict aliasing rule -- часть стандарта C99. Если вы хотите писать
> >> > быстрый переносимый
> >> > код, то вам стоит следовать этому правилу.
> >> >
> >> Ничего про стандартность тут
> >> http://en.wikipedia.org/wiki/Aliasing_(computing) не увидил. А про то
> >> что существуют конфликты с оптимизаторами там есть.
> > Смотрите внимательнее:
> > "...the ISO standard for the C programming language (including its newer
> > C99 edition) specifies that it is illegal (with some exceptions) for
> > pointers of different types to reference the same memory location."
> >
> > --
> > Alexey "Ktirf" Rusakov
> > GNOME Project
> > ALT Linux Team
> >
> > _______________________________________________
> > Sisyphus mailing list
> > Sisyphus@lists.altlinux.org
> > https://lists.altlinux.org/mailman/listinfo/sisyphus
--
Alexey "Ktirf" Rusakov
GNOME Project
ALT Linux Team
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2009-08-07 13:15 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 17:08 Roman Savochenko
2009-08-05 21:34 ` Alexey Rusakov
2009-08-06 7:17 ` Roman Savochenko
2009-08-06 7:59 ` Alexey Rusakov
2009-08-06 16:21 ` Michael Shigorin
2009-08-06 21:10 ` Michael Shigorin
2009-08-06 18:12 ` Kirill A. Shutemov
2009-08-07 5:49 ` Roman Savochenko
2009-08-07 6:28 ` Yuriy Kashirin
2009-08-07 6:31 ` Kirill A. Shutemov
2009-08-07 7:14 ` Roman Savochenko
2009-08-07 7:35 ` Kirill A. Shutemov
2009-08-07 8:14 ` Roman Savochenko
2009-08-07 8:54 ` Kirill A. Shutemov
2009-08-07 8:57 ` Roman Savochenko
2009-08-07 9:14 ` Kirill A. Shutemov
2009-08-07 8:58 ` Alexey Rusakov
2009-08-07 9:02 ` Roman Savochenko
2009-08-07 9:17 ` Alexey Rusakov
2009-08-07 12:59 ` Serge Ryabchun
2009-08-07 13:15 ` Alexey Rusakov [this message]
2009-08-07 15:43 ` Kirill A. Shutemov
2009-08-13 16:04 ` Kirill A. Shutemov
2009-08-17 15:48 ` Alexander Bokovoy
2009-08-17 20:47 ` [sisyphus] ufraw/liblensfun/etc vs gcc Dmitry V. Levin
2009-08-17 21:25 ` Dmitry V. Levin
2009-08-18 8:40 ` Anton V. Boyarshinov
2009-08-19 0:41 ` [sisyphus] liblensfun vs g++ Dmitry V. Levin
2009-08-19 8:27 ` Sergey Vlasov
2009-08-19 8:33 ` Damir
2009-08-19 23:10 ` Dmitry V. Levin
2009-08-17 22:39 ` [sisyphus] liblensfun Dmitry V. Levin
2009-08-18 23:18 ` 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=1249650948.8229.39.camel@latitude.localdomain \
--to=ktirf@altlinux.org \
--cc=sisyphus@lists.altlinux.org \
--cc=sr@osdn.org.ua \
/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 Sisyphus discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/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 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
public-inbox-index sisyphus
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.sisyphus
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git