Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Unspecified Behaviors in C90 - part 3 |
| Date | 2015-07-17 12:14 -0400 |
| Organization | Self |
| Message-ID | <55A929D2.70908@verizon.net> (permalink) |
| References | (5 earlier) <mo3fka$bds$1@dont-email.me> <45ba9b21-0f12-4662-b89a-9f38c63a9486@googlegroups.com> <mo7qaj$4pr$1@dont-email.me> <d4367854-d7f5-45c6-b69b-68add43b8734@googlegroups.com> <mo9l3t$ntj$2@dont-email.me> |
On 07/16/2015 09:19 PM, James Kuyper wrote:
> On 07/16/2015 08:18 PM, David Kleinecke wrote:
>> On Thursday, July 16, 2015 at 1:36:11 AM UTC-7, Richard Heathfield wrote:
>>> On 16/07/15 03:38, David Kleinecke wrote:
>>>>
>>>> What about
>>>> y = f(g(x),h(x));
>>>> where g and h have different non-commutive side-effects on something
>>>> else? Say g(x) = {y=y+2} and h(x) = {y=3*y}
>>>
>>> As I said, well-written C code does not rely on order of evaluation.
>>> What you have there is not well-written C code. Decide on the order of
>>> evaluation you want, and then write the C in such a way that that is
>>> what you get, regardless of how the compiler generates the code.
>>
>> Of course, as it appears today. But as I keep saying -suppose the
>> compiler did respect the order. Would't you want to know?
>
> What do you mean by the phrase "respect the order". This appears to be
> based on the incorrect assumption that there is a particular order to be
> respected. If not, what are you talking about?
I've thought about it a bit, and I've thought of a possible explanation.
Is is possible that you believe the the standard always specifies the
order in which things occur, but gives implementations permission to
optimize by choosing a different order - but only if it doesn't matter
which order they occur in? That incorrect belief would explain most of
the comments you've made recently that talk about respecting the order.
There's an element of truth there. There is an "as-if" rule, though it's
not explicitly labeled as such. The basic concept is that an
implementation can use any method it desires to implement the specified
behavior - it doesn't have to implement it the same way that the
standard describes, but it must always produce the same results as-if it
had been done that way. Rick C Hodgin, among other people, find this
extremely objectionable - he wants C to be nothing more than a
high-level assembler, with a direct one-to-one correspondence between C
language constructs and the generated assembly language. If that's what
he wants, he should be using assembler - C is not, and never was,
intended to be that kind of language.
It is true that the as-if rule permits an implementation to rearrange
the order in which events occur, even if that order is explicitly
specified by the standard, so long as it doesn't matter in terms of the
observable behavior of your program.
When the C standard says that the behavior is unspecified, that's a very
different concept. It is permitted for the behavior of the program to be
detectably different, depending upon which choice the implementation
made. If one of the permitted options would produce behavior that you
don't want to happen, then you're supposed to re-write the code so that
it's no longer a permitted option. Such a re-write is always possible.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-09 11:21 -0700
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-09 14:54 -0400
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-09 21:38 +0100
Re: Unspecified Behaviors in C90 - part 3 raltbos@xs4all.nl (Richard Bos) - 2015-07-13 21:22 +0000
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-14 08:21 -0700
Re: Unspecified Behaviors in C90 - part 3 Keith Thompson <kst-u@mib.org> - 2015-07-14 08:48 -0700
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-14 09:33 -0700
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-14 18:08 +0100
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-15 19:38 -0700
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-16 00:47 -0400
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-16 17:10 -0700
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-16 21:17 -0400
Re: Unspecified Behaviors in C90 - part 3 maddoxr@acm.org - 2015-07-17 07:43 -0700
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-16 09:35 +0100
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-16 17:18 -0700
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 01:45 +0100
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-16 21:19 -0400
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-17 12:14 -0400
Re: Unspecified Behaviors in C90 - part 3 Keith Thompson <kst-u@mib.org> - 2015-07-17 11:00 -0700
Re: Unspecified Behaviors in C90 - part 3 raltbos@xs4all.nl (Richard Bos) - 2015-07-19 21:24 +0000
Re: Unspecified Behaviors in C90 - part 3 Keith Thompson <kst-u@mib.org> - 2015-07-16 07:40 -0700
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-16 17:20 -0700
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 01:49 +0100
Re: Unspecified Behaviors in C90 - part 3 Keith Thompson <kst-u@mib.org> - 2015-07-14 11:23 -0700
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-14 15:11 -0400
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-15 19:46 -0700
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-16 01:50 -0400
Re: Unspecified Behaviors in C90 - part 3 David Kleinecke <dkleinecke@gmail.com> - 2015-07-16 17:15 -0700
Re: Unspecified Behaviors in C90 - part 3 Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 01:39 +0100
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-16 22:26 -0400
Re: Unspecified Behaviors in C90 - part 3 raltbos@xs4all.nl (Richard Bos) - 2015-07-19 21:22 +0000
Re: Unspecified Behaviors in C90 - part 3 James Kuyper <jameskuyper@verizon.net> - 2015-07-19 17:57 -0400
csiph-web