Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16806 > unrolled thread

what is the right value about a = a++;

Started bylujnan <lujnan@gmail.com>
First post2012-02-06 00:10 -0800
Last post2012-02-07 01:18 -0500
Articles 20 on this page of 114 — 30 participants

Back to article view | Back to comp.lang.c


Contents

  what is the right value about  a = a++; lujnan <lujnan@gmail.com> - 2012-02-06 00:10 -0800
    Re: what is the right value about a = a++; Ruben Mikkonen <camu.umac@gmail.com> - 2012-02-06 00:28 -0800
      Re: what is the right value about a = a++; Keith Thompson <kst-u@mib.org> - 2012-02-06 21:27 -0800
        Re: what is the right value about a = a++; Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-02-06 22:39 -0700
    Re: what is the right value about  a = a++; bert <bert.hutchings@btinternet.com> - 2012-02-06 01:45 -0800
      Re: what is the right value about a = a++; lujnan <lujnan@gmail.com> - 2012-02-06 02:33 -0800
        Re: what is the right value about a = a++; "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-02-06 14:57 -0800
        Re: what is the right value about a = a++; Barry Schwarz <schwarzb@dqel.com> - 2012-02-06 22:50 -0800
          Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-07 08:15 +0000
            Re: what is the right value about a = a++; lujnan <lujnan@gmail.com> - 2012-02-07 00:31 -0800
              Re: what is the right value about a = a++; Keith Thompson <kst-u@mib.org> - 2012-02-07 09:07 -0800
                Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-07 17:31 +0000
                  Re: what is the right value about a = a++; Joshua Maurice <joshuamaurice@gmail.com> - 2012-02-09 17:50 -0800
                  Re: what is the right value about a = a++; Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-21 23:42 +0200
                    Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-22 04:28 +0000
                      Re: what is the right value about a = a++; Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-25 00:01 +0200
                      Re: what is the right value about a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-25 02:25 -0500
                        Re: what is the right value about a = a++; Ike Naar <ike@iceland.freeshell.org> - 2012-02-25 09:00 +0000
                          Re: what is the right value about a = a++; Philip Lantz <prl@canterey.us> - 2012-02-25 11:13 -0800
                            Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-25 19:34 +0000
                              Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-25 16:51 -0500
                          Re: what is the right value about a = a++; lawrence.jones@siemens.com - 2012-02-27 16:12 -0500
                            Re: what is the right value about a = a++; Ike Naar <ike@iceland.freeshell.org> - 2012-02-27 22:42 +0000
                              Re: what is the right value about a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-27 18:54 -0500
              Re: what is the right value about a = a++; Barry Schwarz <schwarzb@dqel.com> - 2012-02-07 09:26 -0800
            Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-07 15:12 -0500
              Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-07 21:50 +0000
                Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-07 16:51 -0600
                  Re: what is the right value about a = a++; Robert Wessel <robertwessel2@yahoo.com> - 2012-02-07 22:49 -0600
                    Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-08 14:08 -0600
                      Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 00:18 +0000
                        Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-09 13:06 -0500
                          Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-09 13:58 -0600
                          Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 23:52 +0000
                          Re: what is the right value about a = a++; jgk@panix.com (Joe keane) - 2012-02-10 21:45 +0000
                            Re: what is the right value about a = a++; Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-02-22 00:09 +0200
                      Re: what is the right value about a = a++; Robert Wessel <robertwessel2@yahoo.com> - 2012-02-08 22:35 -0600
                    Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-08 15:42 -0500
                  Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-08 14:47 +0000
                    Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-08 14:29 -0600
                      Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 02:27 +0000
                        Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-09 23:10 -0500
                          Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 09:11 +0000
                            Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 07:26 -0500
                              Re: what is the right value about a = a++; Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-10 13:12 +0000
                                Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 11:07 -0500
                              Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 16:27 +0000
                                Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 12:17 -0500
                                  Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 12:09 -0600
                                    Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-10 18:17 -0500
                                      Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-11 10:15 +0000
                                        Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-13 16:04 -0500
                        Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 12:30 -0600
                    Re: what is the right value about a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-09 21:30 -0500
                      Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 02:48 +0000
                        Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-10 09:49 +0000
                  Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 00:15 +0000
                    Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-09 12:49 -0500
                      Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 23:51 +0000
                Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-08 15:39 -0500
                  Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 01:05 +0000
                    Re: what is the right value about a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-09 23:24 -0500
                      Re: what is the right value about a = a++; Jens Gustedt <jens.gustedt@loria.fr> - 2012-02-10 16:58 +0100
                        Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-10 23:32 +0000
                  Re: what is the right value about a = a++; John Bode <jfbode1029@gmail.com> - 2012-02-08 17:41 -0800
                    Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-08 22:25 -0500
                    Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-09 13:15 -0500
                      Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 23:57 +0000
                        Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-10 11:15 -0500
                          Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 11:58 -0600
                            Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-10 18:14 -0500
                          Re: what is the right value about a = a++; Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-10 22:43 +0000
                        Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 11:53 -0600
                        Re: what is the right value about a = a++; Joshua Maurice <joshuamaurice@gmail.com> - 2012-02-10 15:19 -0800
                  Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 02:32 +0000
                    Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-09 23:13 -0500
                      Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 09:34 +0000
                        Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 07:32 -0500
                          Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-10 22:24 +0000
                        Re: what is the right value about a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-10 11:35 -0500
                          Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 12:23 -0500
                Re: what is the right value about a = a++; falk@rahul.net (Edward A. Falk) - 2012-02-08 20:40 +0000
                  Re: what is the right value about a = a++; Keith Thompson <kst-u@mib.org> - 2012-02-08 15:00 -0800
                  Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 01:10 +0000
                    Re: what is the right value about a = a++; 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-09 20:43 -0800
                      Re: what is the right value about a = a++; Robert Wessel <robertwessel2@yahoo.com> - 2012-02-09 23:36 -0600
                  Re: what is the right value about a = a++; cri@tiac.net (Richard Harter) - 2012-02-10 02:40 +0000
                    Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-09 23:17 -0500
                Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-08 23:49 +0000
              Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-08 23:42 +0000
            Re: what is the right value about a = a++; blp@cs.stanford.edu (Ben Pfaff) - 2012-02-07 12:09 -0800
        Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-07 07:42 -0500
          Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-07 17:21 +0000
            Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-07 15:24 -0600
              Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 01:27 +0000
                Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 21:57 -0600
        Re: what is the right value about a = a++; "Joel C. Salomon" <joelcsalomon@gmail.com> - 2012-02-08 01:00 -0500
        Re: what is the right value about a = a++; falk@rahul.net (Edward A. Falk) - 2012-02-08 20:33 +0000
          Re: what is the right value about a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 02:05 +0000
      Re: what is the right value about  a = a++; Markus Wichmann <nullplan@gmx.net> - 2012-02-09 09:28 +0100
        Re: what is the right value about  a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 10:21 +0000
          Re: what is the right value about  a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-09 11:38 +0000
          Re: what is the right value about  a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-10 00:03 -0500
          Re: what is the right value about  a = a++; Philip Lantz <prl@canterey.us> - 2012-02-10 01:15 -0800
        Re: what is the right value about  a = a++; Kenneth Brody <kenbrody@spamcop.net> - 2012-02-09 13:22 -0500
    Re: what is the right value about a = a++; Slash QB <slashqb@gmail.com> - 2012-02-06 02:35 -0800
      Re: what is the right value about a = a++; Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-07 03:07 -0800
        Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-07 15:19 -0600
          Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-07 17:00 -0500
            Re: what is the right value about a = a++; Stephen Sprunk <stephen@sprunk.org> - 2012-02-10 12:05 -0600
              Re: what is the right value about a = a++; James Kuyper <jameskuyper@verizon.net> - 2012-02-10 13:46 -0500
    Re: what is the right value about  a = a++; Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-02-06 22:37 -0700
      Re: what is the right value about  a = a++; Kaz Kylheku <kaz@kylheku.com> - 2012-02-07 07:22 +0000
    Re: what is the right value about  a = a++; Shao Miller <sha0.miller@gmail.com> - 2012-02-07 01:18 -0500

Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →


#16956 — Re: what is the right value about a = a++;

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-09 01:05 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208161852.146@kylheku.com>
In reply to#16942
On 2012-02-08, Kenneth Brody <kenbrody@spamcop.net> wrote:
> On 2/7/2012 4:50 PM, Richard Harter wrote:
>> On Tue, 07 Feb 2012 15:12:53 -0500, Kenneth Brody
>> <kenbrody@spamcop.net>  wrote:
>>
>>> On 2/7/2012 3:15 AM, Kaz Kylheku wrote:
>>>> On 2012-02-07, Barry Schwarz<schwarzb@dqel.com>   wrote:
>>>>> On Mon, 6 Feb 2012 02:33:24 -0800 (PST), lujnan<lujnan@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> On Feb 6, 5:45 pm, bert<bert.hutchi...@btinternet.com>   wrote:
>>>>>>> On Monday, February 6, 2012 8:10:00 AM UTC, lujnan wrote:
>>>>>>>> b = a = a++;
>>> [...]
>>>> I don't want diagnostics; I want strict left to right evaluation order
>>>> of operands and subexpressions that complete their side effects before
>>>> yielding a value.
>>>
>>> So, what you are really saying, is you want to eliminate most of C's
>>> optimization abilities, by restricting the order in which the expression
>>> *must* be evaluated, and side effects *must* be completed?
>>
>> Well, no, he isn't saying any such thing.  You just made it up.  The
>> fact that evaluation order in C is left to the compilers has very
>> little to do with optimization; it is a historical artifact that came
>> from endorsing existing practice when the ANSI standard was put
>> together.  Existing practice then was that compiler writers could do
>> evaluations in whatever they pleased and they did.
>
> Well, not having access to the Standards committee, I can only speculate. 
> However, if evaluation order were the only thing at stake here, things would 
> have been left as "unspecified" rather than "undefined".

Last I looked, the order is in fact unspecified. But then what is undefined
is the multiple uses of the same object.

So for instance f(g(), h()); is not undefined behavior, but unspecified.
We don't know whether g is called first or h, but there are only two
possibilities.

In /practice/ there is no difference.

Unspecified, undefined: it all translates to hidden bugs in code that are not
caught by your regression test suite---even if that code has 100% coverage!

> In the 30+ years of programming in C, I don't believe I've ever had the need 
> to write code which depended on side-effects being completed in "the right 
> order" within a single statement.

I.e. you have written plenty of code with multiple side effects, but you're
sure that you didn't botch it.

> Whether that's because I know that 
> there's no such thing as "the right order", or because I never came across a 
> scenario where that might be useful, I cannot say, but I'm leaning towards 
> the latter.

I'm not so confident. After 30 years of coding, I'm still making coding
mistakes (even syntax!). I catch these with the help of the compiler, by
reviewing code, by test coverage, or sometimes with the help of other people.

These evaluation order issues fall into a category that is not caught
by tools, and not even by perfect test coverage, because a test case
could simply validate that the expected behavior is happening on the
given target machine and compiler.

I can't justify a belief that the mistakes I make are always, by good luck, in
categories that are caught by the compiler, or by test coverage.

Of course I haven't /knowingly/ stuffed multiple side effects into an
expression such that their order is critical to the correct outcome, for what
that is worth.

[toc] | [prev] | [next] | [standalone]


#17033 — Re: what is the right value about a = a++;

FromShao Miller <sha0.miller@gmail.com>
Date2012-02-09 23:24 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jh261k$676$1@dont-email.me>
In reply to#16956
On 2/8/2012 20:05, Kaz Kylheku wrote:
>
> These evaluation order issues fall into a category that is not caught
> by tools, and not even by perfect test coverage, because a test case
> could simply validate that the expected behavior is happening on the
> given target machine and compiler.
>

What is an example use case for having a defined evaluation order for 
function arguments?  I might have missed one or more.

Is it realistic that an implementation might have a thread of execution 
for each independent branch of evaluation, so that the evaluation order 
of some expressions might be simultaneous?

[toc] | [prev] | [next] | [standalone]


#17054 — Re: what is the right value about a = a++;

FromJens Gustedt <jens.gustedt@loria.fr>
Date2012-02-10 16:58 +0100
SubjectRe: what is the right value about a = a++;
Message-ID<4F353E93.1080007@loria.fr>
In reply to#17033
Am 02/10/2012 05:24 AM, schrieb Shao Miller:
> Is it realistic that an implementation might have a thread of execution
> for each independent branch of evaluation, so that the evaluation order
> of some expressions might be simultaneous?

thread of execution in a broad sense, certainly, such as done for
pipelining processors with out-of-order execution

compilers do reordering of statements all the time, and not imposing a
sequence point between two evaluations is giving the necessary slackness
to the compiler for doing so.

Jens

[toc] | [prev] | [next] | [standalone]


#17100 — Re: what is the right value about a = a++;

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-10 23:32 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120210153039.706@kylheku.com>
In reply to#17054
On 2012-02-10, Jens Gustedt <jens.gustedt@loria.fr> wrote:
> Am 02/10/2012 05:24 AM, schrieb Shao Miller:
>> Is it realistic that an implementation might have a thread of execution
>> for each independent branch of evaluation, so that the evaluation order
>> of some expressions might be simultaneous?
>
> thread of execution in a broad sense, certainly, such as done for
> pipelining processors with out-of-order execution
>
> compilers do reordering of statements all the time, and not imposing a
> sequence point between two evaluations is giving the necessary slackness
> to the compiler for doing so.

That is false. A viable compiler must optimize across sequence points.
The necessary slackness comes from analyzing the data flows in the intermediate
graph structure representing the program.

[toc] | [prev] | [next] | [standalone]


#16959 — Re: what is the right value about a = a++;

FromJohn Bode <jfbode1029@gmail.com>
Date2012-02-08 17:41 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<93794fd7-14e9-4bef-b9bc-f027dd734ce7@o13g2000vbf.googlegroups.com>
In reply to#16942
On Feb 8, 2:39 pm, Kenneth Brody <kenbr...@spamcop.net> wrote:
> On 2/7/2012 4:50 PM, Richard Harter wrote:
>
>
>
> > On Tue, 07 Feb 2012 15:12:53 -0500, Kenneth Brody
> > <kenbr...@spamcop.net>  wrote:

[snip]

> Consider the fact that, in a "well behaved" program, the order of evaluation
> doesn't matter.  Consider, too, that an optimizer may change the order of
> evaluation to something more "efficient" on a given target platform.
>
> The truth of the matter is, is that when, precisely, a side effect most
> efficiently takes effect, is very platform-dependent, and can even vary from
> expression to expression on a given platform.
>

Is this anything more than received wisdom?  Does anyone have a
concrete example (read: generated machine code) showing *how*
rearranging evaluation order can make an operation more efficient?

I mean, I've parroted that line more than once, but I certainly can't
point to an example of where it makes a difference.

[toc] | [prev] | [next] | [standalone]


#16961 — Re: what is the right value about a = a++;

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-08 22:25 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jgvean$8mm$1@dont-email.me>
In reply to#16959
On 02/08/2012 08:41 PM, John Bode wrote:
> Is this anything more than received wisdom?  Does anyone have a
> concrete example (read: generated machine code) showing *how*
> rearranging evaluation order can make an operation more efficient?

As a undergrad, I once had a summer job where I was responsible for
writing some hand-optimized assembler to replace two C subroutines that
had been found to be a bottleneck in a scientific calculation. I no
longer remember the concrete details you're asking for, but I do
remember the general strategies I used, and they all depended upon
rearranging the evaluation order.

On the machine I was writing for, there was one component that could
handle either a division or a sqrt() operation in parallel with
multiplications and additions. The main loop required one division,
followed by a sqrt(), followed by another division. Division and sqrt()
both took much longer than either a multiplication or an addition, so
one of the first things I did was rearrange evaluation so the division
started as early as possible, and was immediately followed by the
sqrt(), which was then followed by the second division, and I rearranged
things so that as many multiplications and additions as possible were
done between the start of the division and the completion of the sqrt().

Another key aspect of this machine was a component that could carry out
the register-based equivalent of fma() in three clock cycles, and could
be working on three different fma() operations at the same time, if they
were each started on a different clock cycle. Because the subroutine was
carrying out matrix multiplications, I could easily arrange to keep that
component busy almost full time, but doing so required rearranging the
order of evaluation extensively.

Finally, one of the key things I could do which the compiler was not
able to do, was to treat three different registers as the elements of a
3-component array. This helped to drastically reduce the number of slow
load and store operations, but it meant that a naive implementation of
the subroutine would have required three times as many registers as were
actually available. I dealt with this by rearranging the order of
evaluation so that the each register could be used to represent the
value of several different variables during the course of the
subroutine, by making sure that the periods of time during which the
register represented each variable didn't overlap. IIRC, if there had
been even a single additional register, I could have completely avoided
using RAM for any of the intermediate steps; as it was, I think there
was only one load and one store per pass through the main loop.

It was my first and last project writing in that assembly language. I
documented as accurately as I could precisely how I had designed it, but
I'm sure it was almost completely unmaintainable. My supervisor expected
me to spend the entire summer on it. I completed it in a couple of
weeks, and sped up the subroutine by a factor of 3.5, which disappointed
me - I'd been expecting a factor of 5. But the relevant subroutine was
going to be keeping hundreds of processors busy with a nearly 100% duty
cycle for several years, so that speed-up easily paid for the cost of my
salary. And most of it would have been impossible if I'd not been free
to rearrange the order of evaluation.

All of my rearrangements conformed to the as-if rule, however, so I'm
not sure they're directly relevant to this discussion. The real issue is
whether declaring certain kinds of behavior undefined makes it easier to
optimize code by mechanisms that would violate the as-if rule if the
behavior were defined. I believe this is the case, but I don't have any
anecdotes that demonstrate that fact.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#16989 — Re: what is the right value about a = a++;

FromKenneth Brody <kenbrody@spamcop.net>
Date2012-02-09 13:15 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<vradnUC0CLnukKnSnZ2dnUVZ_r6dnZ2d@bestweb.net>
In reply to#16959
On 2/8/2012 8:41 PM, John Bode wrote:
> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>  wrote:
[...]
>> The truth of the matter is, is that when, precisely, a side effect most
>> efficiently takes effect, is very platform-dependent, and can even vary from
>> expression to expression on a given platform.
>>
>
> Is this anything more than received wisdom?  Does anyone have a
> concrete example (read: generated machine code) showing *how*
> rearranging evaluation order can make an operation more efficient?
>
> I mean, I've parroted that line more than once, but I certainly can't
> point to an example of where it makes a difference.

foo(a++,a++);

On my system, this code is generated:

         mov     eax, DWORD PTR _a
         push    eax
         push    eax
         add     eax, 2
         mov     DWORD PTR _a, eax
         call    _foo
         add     esp, 8

By delaying the post-increment, the code is more efficient than requiring 
two separate increments.

In fact, the above line of code, when compile w/o any optimization, does the 
"use the stack like an array" as someone else suggested to handle the 
"strict left-to-right evaluation":

tv68 = -8
tv65 = -4
[...]
         mov     ebp, esp
         sub     esp, 8
         mov     eax, DWORD PTR _a
         mov     DWORD PTR tv65[ebp], eax
         mov     ecx, DWORD PTR _a
         mov     DWORD PTR tv68[ebp], ecx
         mov     edx, DWORD PTR _a
         add     edx, 1
         mov     DWORD PTR _a, edx
         mov     eax, DWORD PTR _a
         add     eax, 1
         mov     DWORD PTR _a, eax
         mov     ecx, DWORD PTR tv65[ebp]
         push    ecx
         mov     edx, DWORD PTR tv68[ebp]
         push    edx
         call    _foo
         add     esp, 8

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


#17014 — Re: what is the right value about a = a++;

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-09 23:57 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120209155340.204@kylheku.com>
In reply to#16989
On 2012-02-09, Kenneth Brody <kenbrody@spamcop.net> wrote:
> On 2/8/2012 8:41 PM, John Bode wrote:
>> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>  wrote:
> [...]
>>> The truth of the matter is, is that when, precisely, a side effect most
>>> efficiently takes effect, is very platform-dependent, and can even vary from
>>> expression to expression on a given platform.
>>>
>>
>> Is this anything more than received wisdom?  Does anyone have a
>> concrete example (read: generated machine code) showing *how*
>> rearranging evaluation order can make an operation more efficient?
>>
>> I mean, I've parroted that line more than once, but I certainly can't
>> point to an example of where it makes a difference.
>
> foo(a++,a++);
>
> On my system, this code is generated:
>
>          mov     eax, DWORD PTR _a
>          push    eax
>          push    eax
>          add     eax, 2
>          mov     DWORD PTR _a, eax
>          call    _foo
>          add     esp, 8
>
> By delaying the post-increment, the code is more efficient than requiring 
> two separate increments.

Note that this is still allowed under strict left-right, bottom-up evaluation.

Because a is not volatile, the code does not require two actual increments.
That is merely the abstract semantics.

So this is really tangential to the debate. (Yes, rearranging computations is
important and crucial necessary for optimization.)

[toc] | [prev] | [next] | [standalone]


#17056 — Re: what is the right value about a = a++;

FromKenneth Brody <kenbrody@spamcop.net>
Date2012-02-10 11:15 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<eO6dnYN-d58O36jSnZ2dnUVZ_gednZ2d@bestweb.net>
In reply to#17014
On 2/9/2012 6:57 PM, Kaz Kylheku wrote:
> On 2012-02-09, Kenneth Brody<kenbrody@spamcop.net>  wrote:
>> On 2/8/2012 8:41 PM, John Bode wrote:
>>> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>   wrote:
>> [...]
>>>> The truth of the matter is, is that when, precisely, a side effect most
>>>> efficiently takes effect, is very platform-dependent, and can even vary from
>>>> expression to expression on a given platform.
>>>>
>>>
>>> Is this anything more than received wisdom?  Does anyone have a
>>> concrete example (read: generated machine code) showing *how*
>>> rearranging evaluation order can make an operation more efficient?
>>>
>>> I mean, I've parroted that line more than once, but I certainly can't
>>> point to an example of where it makes a difference.
>>
>> foo(a++,a++);
>>
>> On my system, this code is generated:
>>
>>           mov     eax, DWORD PTR _a
>>           push    eax
>>           push    eax
>>           add     eax, 2
>>           mov     DWORD PTR _a, eax
>>           call    _foo
>>           add     esp, 8
>>
>> By delaying the post-increment, the code is more efficient than requiring
>> two separate increments.
>
> Note that this is still allowed under strict left-right, bottom-up evaluation.

Not according to the "and all side-effects must take place immediately" part 
of the argument.  In that case, the second parameter *must* be one more than 
the original value of a.

> Because a is not volatile, the code does not require two actual increments.
> That is merely the abstract semantics.

True, the as-if rule can be satisfied by the single "add 2" operation, but 
the "side-effects must take place immediately" cannot.

And, making "a" volatile gives this code:

         mov     eax, DWORD PTR _a
         mov     ecx, DWORD PTR _a
         mov     edx, 1
         add     DWORD PTR _a, edx
         add     DWORD PTR _a, edx
         push    eax
         push    ecx
         call    _foo
         add     esp, 8

Now, the two increments are done separately, but the code was still 
rearranged so that they still take place after grabbing the original values 
of "a".  Whether this is faster than moving one of the adds between the two 
reads of "a", I don't know, nor do I have the time or resources to investigate.

> So this is really tangential to the debate. (Yes, rearranging computations is
> important and crucial necessary for optimization.)

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


#17066 — Re: what is the right value about a = a++;

FromStephen Sprunk <stephen@sprunk.org>
Date2012-02-10 11:58 -0600
SubjectRe: what is the right value about a = a++;
Message-ID<jh3ls5$les$1@dont-email.me>
In reply to#17056
On 10-Feb-12 10:15, Kenneth Brody wrote:
> On 2/9/2012 6:57 PM, Kaz Kylheku wrote:
>> Because a is not volatile, the code does not require two actual
>> increments.
>> That is merely the abstract semantics.
> 
> True, the as-if rule can be satisfied by the single "add 2" operation,
> but the "side-effects must take place immediately" cannot.
> 
> And, making "a" volatile gives this code:
> 
>         mov     eax, DWORD PTR _a
>         mov     ecx, DWORD PTR _a
>         mov     edx, 1
>         add     DWORD PTR _a, edx
>         add     DWORD PTR _a, edx
>         push    eax
>         push    ecx
>         call    _foo
>         add     esp, 8
> 
> Now, the two increments are done separately, but the code was still
> rearranged so that they still take place after grabbing the original
> values of "a".  Whether this is faster than moving one of the adds
> between the two reads of "a", I don't know, nor do I have the time or
> resources to investigate.

"Faster" is perhaps irrelevant in this case because _the result is
different_, which shows exactly why invoking undefined behavior can be
such a problem.

The above asm does this:

tmp1 = a;
tmp2 = a;
a = tmp1 + 1;
a = tmp2 + 1;
foo(tmp1, tmp2);

Note that, despite two increments, the final value of a is only _one_
greater than its initial value.

This would not be a valid optimization if there were a sequence point
between arguments, as proposed.

S

-- 
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS        dice at every possible opportunity." --Stephen Hawking

[toc] | [prev] | [next] | [standalone]


#17093 — Re: what is the right value about a = a++;

FromKenneth Brody <kenbrody@spamcop.net>
Date2012-02-10 18:14 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<94Odncp-l6hZOajSnZ2dnUVZ_oednZ2d@bestweb.net>
In reply to#17066
On 2/10/2012 12:58 PM, Stephen Sprunk wrote:
> On 10-Feb-12 10:15, Kenneth Brody wrote:
>> On 2/9/2012 6:57 PM, Kaz Kylheku wrote:
>>> Because a is not volatile, the code does not require two actual
>>> increments.
>>> That is merely the abstract semantics.
>>
>> True, the as-if rule can be satisfied by the single "add 2" operation,
>> but the "side-effects must take place immediately" cannot.
>>
>> And, making "a" volatile gives this code:
>>
>>          mov     eax, DWORD PTR _a
>>          mov     ecx, DWORD PTR _a
>>          mov     edx, 1
>>          add     DWORD PTR _a, edx
>>          add     DWORD PTR _a, edx
>>          push    eax
>>          push    ecx
>>          call    _foo
>>          add     esp, 8
>>
>> Now, the two increments are done separately, but the code was still
>> rearranged so that they still take place after grabbing the original
>> values of "a".  Whether this is faster than moving one of the adds
>> between the two reads of "a", I don't know, nor do I have the time or
>> resources to investigate.
>
> "Faster" is perhaps irrelevant in this case because _the result is
> different_, which shows exactly why invoking undefined behavior can be
> such a problem.

Yes, "foo(a++,a++)" is UB.  However, the OP (I forget who that was at this 
point) was bemoaning the fact that UB exists, and suggested that C should 
make it defined, as Java does.

> The above asm does this:
>
> tmp1 = a;
> tmp2 = a;
> a = tmp1 + 1;
> a = tmp2 + 1;
> foo(tmp1, tmp2);
>
> Note that, despite two increments, the final value of a is only _one_
> greater than its initial value.

Re-read the assembler.  It's equivalent to:

     tmp1 = a;
     tmp2 = a;
     a++;
     a++;
     foo(tmp2,tmp1);

(Note, too, that the arguments are evaluated right-to-left, which is quite 
common, though not guaranteed.)

> This would not be a valid optimization if there were a sequence point
> between arguments, as proposed.

Correct.  Of course, given the lack of sequence points, it's perfectly 
valid.  :-)

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


#17091 — Re: what is the right value about a = a++;

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-02-10 22:43 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<0.b3b92d95a918ce0b4205.20120210224322GMT.87y5sa9unp.fsf@bsb.me.uk>
In reply to#17056
Kenneth Brody <kenbrody@spamcop.net> writes:

> On 2/9/2012 6:57 PM, Kaz Kylheku wrote:
>> On 2012-02-09, Kenneth Brody<kenbrody@spamcop.net>  wrote:
>>> On 2/8/2012 8:41 PM, John Bode wrote:
>>>> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>   wrote:
>>> [...]
>>>>> The truth of the matter is, is that when, precisely, a side effect most
>>>>> efficiently takes effect, is very platform-dependent, and can even vary from
>>>>> expression to expression on a given platform.
>>>>>
>>>>
>>>> Is this anything more than received wisdom?  Does anyone have a
>>>> concrete example (read: generated machine code) showing *how*
>>>> rearranging evaluation order can make an operation more efficient?
>>>>
>>>> I mean, I've parroted that line more than once, but I certainly can't
>>>> point to an example of where it makes a difference.
>>>
>>> foo(a++,a++);
>>>
>>> On my system, this code is generated:
>>>
>>>           mov     eax, DWORD PTR _a
>>>           push    eax
>>>           push    eax
>>>           add     eax, 2
>>>           mov     DWORD PTR _a, eax
>>>           call    _foo
>>>           add     esp, 8
>>>
>>> By delaying the post-increment, the code is more efficient than requiring
>>> two separate increments.
>>
>> Note that this is still allowed under strict left-right, bottom-up evaluation.
>
> Not according to the "and all side-effects must take place
> immediately" part of the argument.  In that case, the second parameter
> *must* be one more than the original value of a.
>
>> Because a is not volatile, the code does not require two actual increments.
>> That is merely the abstract semantics.
>
> True, the as-if rule can be satisfied by the single "add 2" operation,
> but the "side-effects must take place immediately" cannot.

I don't follow this reasoning.  The as-if rule can be used to justify
removing the increments entirely (if a is not reference later, for
example) so I don't see why it can't be used to justify their happening
together.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#17065 — Re: what is the right value about a = a++;

FromStephen Sprunk <stephen@sprunk.org>
Date2012-02-10 11:53 -0600
SubjectRe: what is the right value about a = a++;
Message-ID<jh3li5$jnk$1@dont-email.me>
In reply to#17014
On 09-Feb-12 17:57, Kaz Kylheku wrote:
> On 2012-02-09, Kenneth Brody <kenbrody@spamcop.net> wrote:
>> On 2/8/2012 8:41 PM, John Bode wrote:
>>> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>  wrote:
>> [...]
>>>> The truth of the matter is, is that when, precisely, a side effect most
>>>> efficiently takes effect, is very platform-dependent, and can even vary from
>>>> expression to expression on a given platform.
>>>>
>>>
>>> Is this anything more than received wisdom?  Does anyone have a
>>> concrete example (read: generated machine code) showing *how*
>>> rearranging evaluation order can make an operation more efficient?
>>>
>>> I mean, I've parroted that line more than once, but I certainly can't
>>> point to an example of where it makes a difference.
>>
>> foo(a++,a++);
>>
>> On my system, this code is generated:
>>
>>          mov     eax, DWORD PTR _a
>>          push    eax
>>          push    eax
>>          add     eax, 2
>>          mov     DWORD PTR _a, eax
>>          call    _foo
>>          add     esp, 8
>>
>> By delaying the post-increment, the code is more efficient than requiring 
>> two separate increments.
> 
> Note that this is still allowed under strict left-right, bottom-up evaluation.

My interpretation of "strict left-to-right" evaluation is equivalent to
this:

tmp1 = a++;
tmp2 = a++;
foo(tmp1, tmp2);

So, this would be a valid optimization:

foo(a, a+1);
a+=2;

In contrast, the above asm has the side effect of the first "a++"
expression occurring _after_ the evaluation of the second expressions,
like this:

foo(a, a);
a+=2;

> Because a is not volatile, the code does not require two actual increments.
> That is merely the abstract semantics.

Of course.  However, when exactly each postincrement happens _in the
virtual machine_ does affect the value of the second argument to foo().

S

-- 
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS        dice at every possible opportunity." --Stephen Hawking

[toc] | [prev] | [next] | [standalone]


#17096 — Re: what is the right value about a = a++;

FromJoshua Maurice <joshuamaurice@gmail.com>
Date2012-02-10 15:19 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<45942bdf-c9c4-4b20-bbd2-d1f403d1228a@x6g2000pbk.googlegroups.com>
In reply to#17014
On Feb 9, 3:57 pm, Kaz Kylheku <k...@kylheku.com> wrote:
> On 2012-02-09, Kenneth Brody <kenbr...@spamcop.net> wrote:
>
>
>
>
>
>
>
>
>
> > On 2/8/2012 8:41 PM, John Bode wrote:
> >> On Feb 8, 2:39 pm, Kenneth Brody<kenbr...@spamcop.net>  wrote:
> > [...]
> >>> The truth of the matter is, is that when, precisely, a side effect most
> >>> efficiently takes effect, is very platform-dependent, and can even vary from
> >>> expression to expression on a given platform.
>
> >> Is this anything more than received wisdom?  Does anyone have a
> >> concrete example (read: generated machine code) showing *how*
> >> rearranging evaluation order can make an operation more efficient?
>
> >> I mean, I've parroted that line more than once, but I certainly can't
> >> point to an example of where it makes a difference.
>
> > foo(a++,a++);
>
> > On my system, this code is generated:
>
> >          mov     eax, DWORD PTR _a
> >          push    eax
> >          push    eax
> >          add     eax, 2
> >          mov     DWORD PTR _a, eax
> >          call    _foo
> >          add     esp, 8
>
> > By delaying the post-increment, the code is more efficient than requiring
> > two separate increments.
>
> Note that this is still allowed under strict left-right, bottom-up evaluation.
>
> Because a is not volatile, the code does not require two actual increments.
> That is merely the abstract semantics.
>
> So this is really tangential to the debate. (Yes, rearranging computations is
> important and crucial necessary for optimization.)

I'm sorry for potentially derailing this conversation, but this is one
of my pet peeves. You do know that volatile - apart from correct
signal handling and setjump longjump nonsense - is completely useless
in portable code, right? When you said "because a is not volatile",
you are immediately assuming several things about volatile which are
not true, and have never been true, and will not be true in C11. A
perfectly conforming implementation is free to basically ignore
volatile and compile it down as if it wasn't there. The semantics of
the C abstract machine do not specify what exactly a volatile write
"means". They just say that it's part of the visible behavior of the
abstract machine, while the standard does not define what that means.

As a matter of facts of current implementations, I have been told by
reliable people that volatile is insufficient alone to do MMIO on most
modern machines, rendering its original purpose moot. volatile is a
relic with no support from most compilers nowadays - apart from some
incredibly non-portable use in some kernel code, and with the advent
of C11, it should hopefully become extinct (again apart from setjump
longjump nonsense and legacy code).

[toc] | [prev] | [next] | [standalone]


#17026 — Re: what is the right value about a = a++;

Fromcri@tiac.net (Richard Harter)
Date2012-02-10 02:32 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<4f3480fe.425035207@text.giganews.com>
In reply to#16942
On Wed, 08 Feb 2012 15:39:33 -0500, Kenneth Brody
<kenbrody@spamcop.net> wrote:


>In the 30+ years of programming in C, I don't believe I've ever had the need 
>to write code which depended on side-effects being completed in "the right 
>order" within a single statement.  Whether that's because I know that 
>there's no such thing as "the right order", or because I never came across a 
>scenario where that might be useful, I cannot say, but I'm leaning towards 
>the latter.

In my 30 odd years of programming in C I've come across cases where
the code only worked because of side-effects being completed in the
right order.  The problem is that I don't know what cases I've missed,
and, to be honest, I suspect you haven't either.

 

[toc] | [prev] | [next] | [standalone]


#17031 — Re: what is the right value about a = a++;

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-09 23:13 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jh25hp$3sk$2@dont-email.me>
In reply to#17026
On 02/09/2012 09:32 PM, Richard Harter wrote:
> On Wed, 08 Feb 2012 15:39:33 -0500, Kenneth Brody
> <kenbrody@spamcop.net> wrote:
...
> In my 30 odd years of programming in C I've come across cases where

That sentence would work better with a quantifier of some kind before
the word "cases" - "many", "few", "a fair number", etc.

> the code only worked because of side-effects being completed in the
> right order.

You weren't the author, I hope? Can you provide an example?
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#17046 — Re: what is the right value about a = a++;

Fromcri@tiac.net (Richard Harter)
Date2012-02-10 09:34 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<4f34df6f.449213069@text.giganews.com>
In reply to#17031
On Thu, 09 Feb 2012 23:13:44 -0500, James Kuyper
<jameskuyper@verizon.net> wrote:

>On 02/09/2012 09:32 PM, Richard Harter wrote:
>> On Wed, 08 Feb 2012 15:39:33 -0500, Kenneth Brody
>> <kenbrody@spamcop.net> wrote:
>...
>> In my 30 odd years of programming in C I've come across cases where
>
>That sentence would work better with a quantifier of some kind before
>the word "cases" - "many", "few", "a fair number", etc.

Few works.  The problem is that in times of yore (pre-ansi) the rules
were different.  The ultimate authority about the legitimacy of C code
on a given machine was the compiler.  If your code had to run on
twenty different machines then you built and tested it on all of those
machines.  Any thing that didn't work, regardless of whether or not it
"should have" was a bug.  

>
>> the code only worked because of side-effects being completed in the
>> right order.
>
>You weren't the author, I hope? Can you provide an example?

At this remove there is only one case that I am certain of and that
only because it was discussed in comp.lang.c.  I will scrounge around
and see if I can find it.

[toc] | [prev] | [next] | [standalone]


#17051 — Re: what is the right value about a = a++;

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-10 07:32 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jh32pc$4d2$1@dont-email.me>
In reply to#17046
On 02/10/2012 04:34 AM, Richard Harter wrote:
> On Thu, 09 Feb 2012 23:13:44 -0500, James Kuyper
> <jameskuyper@verizon.net> wrote:
> 
>> On 02/09/2012 09:32 PM, Richard Harter wrote:
>>> On Wed, 08 Feb 2012 15:39:33 -0500, Kenneth Brody
>>> <kenbrody@spamcop.net> wrote:
>> ...
>>> In my 30 odd years of programming in C I've come across cases where
>>
>> That sentence would work better with a quantifier of some kind before
>> the word "cases" - "many", "few", "a fair number", etc.
> 
> Few works.  The problem is that in times of yore (pre-ansi) the rules
> were different.  The ultimate authority about the legitimacy of C code
> on a given machine was the compiler.  If your code had to run on
> twenty different machines then you built and tested it on all of those
> machines.  Any thing that didn't work, regardless of whether or not it
> "should have" was a bug.

Well, yes - pre-ANSI was a different issue. In the post-ANSI C world,
however, any code that relied upon the order in which side-effects
occurred, when that order was unspecified by the C standard, was
defective. In general, I'm a big believer in the concept that not all
code needs to be portable - but this particular kind of non-portability
doesn't seem to have any value. You can always re-write the code to
guarantee the desired order of side-effects, and the result of doing so
is usually code that would still be clearer than the original even if
the standard were changed to specify the order of the side effects in
the original.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#17090 — Re: what is the right value about a = a++;

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-10 22:24 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120210142223.395@kylheku.com>
In reply to#17051
On 2012-02-10, James Kuyper <jameskuyper@verizon.net> wrote:
> defective. In general, I'm a big believer in the concept that not all
> code needs to be portable - but this particular kind of non-portability
> doesn't seem to have any value.

Precisely! It is a "gratuitous" nonportability that is not linked to
any operating system or hardware issue. Gee, let's arbitrarily make certain
expression combinations have unspecified or undefined behavior, even though
they contain valid operations on valid operands.

[toc] | [prev] | [next] | [standalone]


#17058 — Re: what is the right value about a = a++;

FromKenneth Brody <kenbrody@spamcop.net>
Date2012-02-10 11:35 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<qNmdnSGgb8Xs2qjSnZ2dnUVZ_oGdnZ2d@bestweb.net>
In reply to#17046
On 2/10/2012 4:34 AM, Richard Harter wrote:
> On Thu, 09 Feb 2012 23:13:44 -0500, James Kuyper
> <jameskuyper@verizon.net>  wrote:
>
>> On 02/09/2012 09:32 PM, Richard Harter wrote:
>>> On Wed, 08 Feb 2012 15:39:33 -0500, Kenneth Brody
>>> <kenbrody@spamcop.net>  wrote:
>> ...
>>> In my 30 odd years of programming in C I've come across cases where
>>
>> That sentence would work better with a quantifier of some kind before
>> the word "cases" - "many", "few", "a fair number", etc.
>
> Few works.  The problem is that in times of yore (pre-ansi) the rules
> were different.  The ultimate authority about the legitimacy of C code
> on a given machine was the compiler.  If your code had to run on
> twenty different machines then you built and tested it on all of those
> machines.  Any thing that didn't work, regardless of whether or not it
> "should have" was a bug.
[...]

Pre-ansi days were certainly "fun" (FSVO).

Of course, given that the first major C project I worked on needed to run on 
both a 68000-based (32-bit big-endian) Unix system and an 8088-based (16-bit 
little-endian) MS-DOS system, I quickly learned how to handle such things.

I also learned (the hard way) not to use bit-fields on things written to 
disk, when we used a compiler which allocated bits in the opposite order. 
(Does the current Standard require a certain order?  ie: if you have 
"unsigned int foo:1", is it required to be either at the MSB or LSB?)

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


Page 4 of 6 — ← Prev page 1 2 3 [4] 5 6  Next page →

Back to top | Article view | comp.lang.c


csiph-web