Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Performance of unaligned memory-accesses Date: Wed, 14 Aug 2019 15:04:50 -0700 Organization: None to speak of Lines: 37 Message-ID: References: <_ic4F.727$t92.96@fx25.am4> <7yd4F.2$CO2.0@fx30.am4> <86mugb7lvg.fsf@mailhub.linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="fac318e141f55b5609bb39e7c100fcd0"; logging-data="7000"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jldNZpiiQ4fLCGE4OovtG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:GFIBYcjr88vlVUVv2aTbm+Hhvfk= sha1:E2yjqFuE9UtycO1MusHHp6n1T6E= Xref: csiph.com comp.lang.c++:67658 Öö Tiib writes: > On Wednesday, 14 August 2019 21:51:32 UTC+3, Bonita Montero wrote: >> >> As I said that's not undefined behaviour because the compiler would >> >> be unable to generate the code as expected but because the CPU might >> >> fail / trap an unaligned access at runtime and the OS might emulate >> >> tzhe unaligned access or not. So it depends on the platform you >> >> target. >> >> > If a given operation has undefined behavior, it doesn't stop >> > having undefined behavior just because it happens to do what >> > you want it to. >> >> In theory, but in practice it has an expectable behaviour depending >> on the platform. > > So it may change because of change of compiler, its version, compiling > options, device that it is ran on, settings of operating system or > other (possibly unrelated) code in same code-base. > Program that happens to do something in narrow conditions but not in > others is unreliable and unreliability is the most disliked property > of software. It's important to remember what "undefined behavior" means. It's not "this program will blow up". It is simply behavior for which this document imposes no requirements where "this document" is the C++ standard. If something other than the standard imposes requirements, it's still undefined behavior. If you want to talk about unexpected or undesirable behavior, call it that. That's not what "undefined behavior" means. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */