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 1 of 6  [1] 2 3 4 5 6  Next page →


#16806 — what is the right value about a = a++;

Fromlujnan <lujnan@gmail.com>
Date2012-02-06 00:10 -0800
Subjectwhat is the right value about a = a++;
Message-ID<108ef91b-e64a-426e-adc1-3651be946377@o4g2000pbc.googlegroups.com>
in GCC and VS2008
the fllow code

int a = 0, b;
b = a = a++;
printf("%d, %d\n", a, b);

result is : 1, 0

in Java

they are all 0.

[toc] | [next] | [standalone]


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

FromRuben Mikkonen <camu.umac@gmail.com>
Date2012-02-06 00:28 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<d1886ec1-5cc3-4d53-82d6-75cc928f31a6@m5g2000yqk.googlegroups.com>
In reply to#16806
On 6 helmi, 10:10, lujnan <luj...@gmail.com> wrote:
> in GCC and VS2008
> the fllow code
>
> int a = 0, b;
> b = a = a++;
> printf("%d, %d\n", a, b);
>
> result is : 1, 0
>
> in Java
>
> they are all 0.


I think that a = a++ means
the following: first a = a,
and then you increase a by 1.
So in my opinion, the
statement should equal to
a = a+1, or a++.

However, in the statement
b = a = a++, the case is
that first you insert a to
be and then a++ to a (a to
a and then increase it by
1). Thus, b equals 0 and
a equals 1.

From the aforementioned
follows that Java sucks
and GCC sucks less.

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


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

FromKeith Thompson <kst-u@mib.org>
Date2012-02-06 21:27 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<lnfwennrgs.fsf@nuthaus.mib.org>
In reply to#16807
Ruben Mikkonen <camu.umac@gmail.com> writes:
[...]
> I think that a = a++ means the following: first a = a, and then you
> increase a by 1.  So in my opinion, the statement should equal to a =
> a+1, or a++.
[...]

This is not a matter of opinion.  As has been stated countless times,
the behavior is undefined -- not just the result of the expression,
or the values assigned to a, but the behavior of any program that
evaluates that expression.  It can do exactly what you expect it
to do, it can crash your program, it can reformat your hard drive.

What "a = a++" really means is that the person who wrote it
does not understand C well enough, and has not read the FAQ at
<http://c-faq.com>.  (Both problems are curable).

Whatever you intended to do, there's certainly a better way to
express it.  If you just want to increment a, just write "a++";
that already assigns the new value to a, so there's no need for an
assignment operator in addition to that.  The "++" operator is not
just a fancy way of writing "+ 1".

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


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

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2012-02-06 22:39 -0700
SubjectRe: what is the right value about a = a++;
Message-ID<1b8vkf9p7m.fsf@pfeifferfamily.net>
In reply to#16816
Keith Thompson <kst-u@mib.org> writes:

> Ruben Mikkonen <camu.umac@gmail.com> writes:
> [...]
>> I think that a = a++ means the following: first a = a, and then you
>> increase a by 1.  So in my opinion, the statement should equal to a =
>> a+1, or a++.
> [...]
>
> This is not a matter of opinion.  As has been stated countless times,
> the behavior is undefined -- not just the result of the expression,
> or the values assigned to a, but the behavior of any program that
> evaluates that expression.  It can do exactly what you expect it
> to do, it can crash your program, it can reformat your hard drive.
>
> What "a = a++" really means is that the person who wrote it
> does not understand C well enough, and has not read the FAQ at
> <http://c-faq.com>.  (Both problems are curable).
>
> Whatever you intended to do, there's certainly a better way to
> express it.  If you just want to increment a, just write "a++";
> that already assigns the new value to a, so there's no need for an
> assignment operator in addition to that.  The "++" operator is not
> just a fancy way of writing "+ 1".

Urrgh.  I stand corrected (in the past I've made fruitless tries at
cancelling posts I've made that are wrong; since there's no real point
I'll just recognize that I was wrong now, and ignore the corrections to
my post that are sure to follow).

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


#16808

Frombert <bert.hutchings@btinternet.com>
Date2012-02-06 01:45 -0800
Message-ID<23133349.4034.1328521513175.JavaMail.geo-discussion-forums@yqfa18>
In reply to#16806
On Monday, February 6, 2012 8:10:00 AM UTC, lujnan wrote:
> b = a = a++;

The question is posted in this group many times. 
Read the FAQ.  The result is undefined - that is, 
it is DEFINED to be undefined.  That means it is 
okay for the result to be different in different 
compilers, and it is even okay for it to be 
different in the same compiler in different 
places or at different times.
-- 

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


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

Fromlujnan <lujnan@gmail.com>
Date2012-02-06 02:33 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<bf40ad26-3199-441e-a524-acf38177273f@og8g2000pbb.googlegroups.com>
In reply to#16808
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++;
>
> The question is posted in this group many times.
> Read the FAQ.  The result is undefined - that is,
> it is DEFINED to be undefined.  That means it is
> okay for the result to be different in different
> compilers, and it is even okay for it to be
> different in the same compiler in different
> places or at different times.
> --

maybe it shows the c world is not perfect. in this point i like the
define of java.
Why C Standards Committee does not constrain this case.

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


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

From"christian.bau" <christian.bau@cbau.wanadoo.co.uk>
Date2012-02-06 14:57 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<1e443eaf-db41-44ad-8756-ee79d5f11e82@x19g2000yqh.googlegroups.com>
In reply to#16809
On Feb 6, 10:33 am, lujnan <luj...@gmail.com> wrote:

> maybe it shows the c world is not perfect. in this point i like the
> define of java.
> Why C Standards Committee does not constrain this case.

First case: a = a++;
Well, that's just pointless code.

Second case: *p = (*q)++;
If p and q are different, then the assignment to *p and the increment
of *q can happen in arbitrary order. The compiler can do both
operations in the order that produces the fastest code, or just do
both operations in arbitrary order. It would be just daft to force the
compiler to use a particular order and possibly producing slower code
just for the totally unlikely case that p and q are the same, that is
just daft.

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


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

FromBarry Schwarz <schwarzb@dqel.com>
Date2012-02-06 22:50 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<8uh1j7t7tkqu9jdu920cgurbnrn2hi3anl@4ax.com>
In reply to#16809
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++;
>>
>> The question is posted in this group many times.
>> Read the FAQ.  The result is undefined - that is,
>> it is DEFINED to be undefined.  That means it is
>> okay for the result to be different in different
>> compilers, and it is even okay for it to be
>> different in the same compiler in different
>> places or at different times.
>> --
>
>maybe it shows the c world is not perfect. in this point i like the
>define of java.
>Why C Standards Committee does not constrain this case.

They did.  They put explicit text in the language standard that
specifically states that this type of expression produces undefined
behavior.

Since one group of people with significant input to the standard is
the compiler writers, the committee accepted their assertion that
forcing the compiler to diagnose most kinds of undefined behavior is
just not practical.

What more would you want and how much are you willing to pay for it?
Not just initial money outlay but also extended compile times,
additional diagnostics that require documentation, etc.  Since some
forms of undefined behavior can only be detected during execution, you
will also have larger program sizes and slower execution speeds.  "Be
careful what you wish for" is good advice.

-- 
Remove del for email

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-07 08:15 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120207090433.476@kylheku.com>
In reply to#16823
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++;
>>>
>>> The question is posted in this group many times.
>>> Read the FAQ.  The result is undefined - that is,
>>> it is DEFINED to be undefined.  That means it is
>>> okay for the result to be different in different
>>> compilers, and it is even okay for it to be
>>> different in the same compiler in different
>>> places or at different times.
>>> --
>>
>>maybe it shows the c world is not perfect. in this point i like the
>>define of java.
>>Why C Standards Committee does not constrain this case.
>
> They did.  They put explicit text in the language standard that
> specifically states that this type of expression produces undefined
> behavior.
>
> Since one group of people with significant input to the standard is
> the compiler writers, the committee accepted their assertion that
> forcing the compiler to diagnose most kinds of undefined behavior is
> just not practical.

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.

Making it unspecified and then trying to catch violations is an
example of silly make-work: creating complexity and then trying
to conquer it, for no benefit.

This unspecified order of evaluation is a throwback to 1980,
when *dst++ = *src++ generated better code than *dst = *src; src++; dst++.

Once upon a time, you had to stuff multiple side effects into the same
expression to get better code because the compiler was following some
naive syntax-directed translation scheme.

> forms of undefined behavior can only be detected during execution, you
> will also have larger program sizes and slower execution speeds.

Wouldn't /that/ be dumb, given that the (now false) rationale for this
unspecified evaluation order business is to get faster code without
working hard in the compiler.

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


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

Fromlujnan <lujnan@gmail.com>
Date2012-02-07 00:31 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<8ae50e32-0538-4efa-832a-81350d4dbd0b@o4g2000pbc.googlegroups.com>
In reply to#16825
> 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.

i agree with your point of view.

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


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

FromKeith Thompson <kst-u@mib.org>
Date2012-02-07 09:07 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<lnbopao9m8.fsf@nuthaus.mib.org>
In reply to#16827
lujnan <lujnan@gmail.com> writes:
>> 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.
>
> i agree with your point of view.

Then you don't want C.

There are valid reasons for the way C leaves some expression evaluations
undefined.  It gives compilers freedom to perform certain optimizations,
which makes for faster code.  And code whose behavior is undefined tends
to be unclear, and would better be written in a different way whose
behavior is well defined.

Even in a language that defines its behavior, "a = a++" is bad code.


-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-07 17:31 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120207091512.859@kylheku.com>
In reply to#16843
On 2012-02-07, Keith Thompson <kst-u@mib.org> wrote:
> lujnan <lujnan@gmail.com> writes:
>>> 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.
>>
>> i agree with your point of view.
>
> Then you don't want C.

You could say that to anyone who is working on the next standard.

Those who worked on C11 didn't want C99, and those who worked on C99
didn't want C90.

> There are valid reasons for the way C leaves some expression evaluations
> undefined. 

No, there are not. There are only outdated beliefs rooted in computer
science shamanism.

Fact is, defined order is safe. Safety is the number one goal in engineering.

> It gives compilers freedom to perform certain optimizations,

No, it allows *programmers* to perform optimizations, when using
compilers from early 1980-something.

> which makes for faster code.  And code whose behavior is undefined tends

Modern compilers can rearrange code substantially, on a large scale,
way beyond the space between two sequence points.

> to be unclear, and would better be written in a different way whose

It's only unclear because it is undefined. If you have a rule like
subexpressions are evaluated from left to right, before parent expressions,
and each expression is fully evaluated before the next expression,
then all these expressions become perspiciously clear. Let's take
a[i] = i++. The main operator is =, so it is evaluated last.
a[i] is evaluated first because it is on the left. Then i++ is evaluated,
producing the prior value of i. Then that value is moved into a[i]
(the original a[i] of course: once a[i] is evaluated it ceases
to be a moving target.)

> behavior is well defined.

Yes, would better be. Would, should does not add up to will.

Code will not rewrite itself.

That ambiguous expression is sitting in the codebase somewhere, and you don't
even know. 

And the intent? It died with the guy who left the company several years ago and
then got run over by a bus.

You're out of your intellectual league here, Kiki.

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


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

FromJoshua Maurice <joshuamaurice@gmail.com>
Date2012-02-09 17:50 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<dbc53114-4361-48d8-bd22-63af8d20983b@vh10g2000pbc.googlegroups.com>
In reply to#16849
On Feb 7, 9:31 am, Kaz Kylheku <k...@kylheku.com> wrote:
> Fact is, defined order is safe. Safety is the number one goal in engineering.

The entire argument of this thread can probably safely be skipped,
given that this assertion has been made.

In short, Kaz is wrong. There are always tradeoffs between safety,
cost, time to market, maintainability, extensibility, and so on.
Sometimes they do go hand in hand. Sometimes they clearly don't.
Different projects have different concerns, different weights on these
tradeoffs.

Nothing further need be said to safely dismiss this incredibly naive
view espoused by Kaz.

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


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

FromPhil Carmody <thefatphil_demunged@yahoo.co.uk>
Date2012-02-21 23:42 +0200
SubjectRe: what is the right value about a = a++;
Message-ID<87mx8bsw1s.fsf@bazspaz.fatphil.org>
In reply to#16849
Kaz Kylheku <kaz@kylheku.com> writes:
> On 2012-02-07, Keith Thompson <kst-u@mib.org> wrote:
> > lujnan <lujnan@gmail.com> writes:
> >>> 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.
> >>
> >> i agree with your point of view.
> >
> > Then you don't want C.
> 
> You could say that to anyone who is working on the next standard.
> 
> Those who worked on C11 didn't want C99, and those who worked on C99
> didn't want C90.
> 
> > There are valid reasons for the way C leaves some expression evaluations
> > undefined. 
> 
> No, there are not. There are only outdated beliefs rooted in computer
> science shamanism.

Tosh. What was being asked for was the removal of CSE elimination for a 
start. Any compiler too dumb not to do CSE elimination is not one I'd 
chose to use, and any language that forbids CSE elimination is one I 
would have no interest in learning anything more about. This is not 
shamanism, this is common sense.

Phil
-- 
> I'd argue that there is much evidence for the existence of a God.
Pics or it didn't happen.
-- Tom (/. uid 822)

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-22 04:28 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120221202308.39@kylheku.com>
In reply to#17751
On 2012-02-21, Phil Carmody <thefatphil_demunged@yahoo.co.uk> wrote:
> Kaz Kylheku <kaz@kylheku.com> writes:
>> On 2012-02-07, Keith Thompson <kst-u@mib.org> wrote:
>> > lujnan <lujnan@gmail.com> writes:
>> >>> 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.
>> >>
>> >> i agree with your point of view.
>> >
>> > Then you don't want C.
>> 
>> You could say that to anyone who is working on the next standard.
>> 
>> Those who worked on C11 didn't want C99, and those who worked on C99
>> didn't want C90.
>> 
>> > There are valid reasons for the way C leaves some expression evaluations
>> > undefined. 
>> 
>> No, there are not. There are only outdated beliefs rooted in computer
>> science shamanism.
>
> Tosh. What was being asked for was the removal of CSE elimination for a 
> start. Any compiler too dumb not to do CSE elimination is not one I'd 
> chose to use, and any language that forbids CSE elimination is one I 
> would have no interest in learning anything more about. This is not 
> shamanism, this is common sense.

CSE elimination in C compilers is not rooted in unspecified evaluation order,
but in the freedom to optimize, so long as the externally visible behavior
agrees in some ways with the abstract behavior. 

You don't have to evaluate a similar expression twice, if it makes no
difference (side-effect wise).

The following has to produce two x's, even now; though we don't know which
expression's x is printed first:

  putchar('x') + putchar('x');

the putchar('x') common subexpression can't be (entirely) reduced to one
instance because there is an external function call which may have a side
effect (and does).

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


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

FromPhil Carmody <thefatphil_demunged@yahoo.co.uk>
Date2012-02-25 00:01 +0200
SubjectRe: what is the right value about a = a++;
Message-ID<871upjriui.fsf@bazspaz.fatphil.org>
In reply to#17767
Kaz Kylheku <kaz@kylheku.com> writes:
> On 2012-02-21, Phil Carmody <thefatphil_demunged@yahoo.co.uk> wrote:
> > Kaz Kylheku <kaz@kylheku.com> writes:
> >> On 2012-02-07, Keith Thompson <kst-u@mib.org> wrote:
> >> > lujnan <lujnan@gmail.com> writes:
> >> >>> 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.
> >> >>
> >> >> i agree with your point of view.
> >> >
> >> > Then you don't want C.
> >> 
> >> You could say that to anyone who is working on the next standard.
> >> 
> >> Those who worked on C11 didn't want C99, and those who worked on C99
> >> didn't want C90.
> >> 
> >> > There are valid reasons for the way C leaves some expression evaluations
> >> > undefined. 
> >> 
> >> No, there are not. There are only outdated beliefs rooted in computer
> >> science shamanism.
> >
> > Tosh. What was being asked for was the removal of CSE elimination for a 
> > start. Any compiler too dumb not to do CSE elimination is not one I'd 
> > chose to use, and any language that forbids CSE elimination is one I 
> > would have no interest in learning anything more about. This is not 
> > shamanism, this is common sense.
> 
> CSE elimination in C compilers is not rooted in unspecified evaluation order,
> but in the freedom to optimize, so long as the externally visible behavior
> agrees in some ways with the abstract behavior. 
> 
> You don't have to evaluate a similar expression twice, if it makes no
> difference (side-effect wise).

Then it's not "strict", it's "as if". But the word "strict" was explicitly 
there above.

Phil
-- 
> I'd argue that there is much evidence for the existence of a God.
Pics or it didn't happen.
-- Tom (/. uid 822)

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


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

FromShao Miller <sha0.miller@gmail.com>
Date2012-02-25 02:25 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jia2d8$a6q$1@dont-email.me>
In reply to#17767
On 2/21/2012 23:28, Kaz Kylheku wrote:
> The following has to produce two x's, even now; though we don't know which
> expression's x is printed first:
>
>    putchar('x') + putchar('x');
>

Doesn't that output a "bold 'x'" if they are evaluated simultaneously?

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


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

FromIke Naar <ike@iceland.freeshell.org>
Date2012-02-25 09:00 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<slrn3vfsjkh8p4.86j.ike@iceland.freeshell.org>
In reply to#17911
On 2012-02-25, Shao Miller <sha0.miller@gmail.com> wrote:
> On 2/21/2012 23:28, Kaz Kylheku wrote:
>> The following has to produce two x's, even now; though we don't know which
>> expression's x is printed first:
>>
>>    putchar('x') + putchar('x');
>>
>
> Doesn't that output a "bold 'x'" if they are evaluated simultaneously?

Doesn't 6.5.2.2 p 10 forbid simultaneous evaluation?

6.5.2.2

10 There is a sequence point after the evaluations of the function
designator and the actual arguments but before the actual call.
Every evaluation in the calling function (including other function
calls) that is not otherwise specically sequenced before or after
the execution of the body of the called function is indeterminately
sequenced with respect to the execution of the called function. 94)

94)
In other words, function executions do not interleave with each other.

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


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

FromPhilip Lantz <prl@canterey.us>
Date2012-02-25 11:13 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<MPG.29b2d29b3cb3629998968e@news.eternal-september.org>
In reply to#17916
Ike Naar wrote:
> On 2012-02-25, Shao Miller <sha0.miller@gmail.com> wrote:
> > On 2/21/2012 23:28, Kaz Kylheku wrote:
> >>    putchar('x') + putchar('x');
> > 
> > Doesn't that output a "bold 'x'" if they are evaluated
> > simultaneously?
> 
> Doesn't 6.5.2.2 p 10 forbid simultaneous evaluation?

Doesn't anybody here understand a joke?

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


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

Fromcri@tiac.net (Richard Harter)
Date2012-02-25 19:34 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<4f493779.736937381@text.giganews.com>
In reply to#17943
On Sat, 25 Feb 2012 11:13:06 -0800, Philip Lantz <prl@canterey.us>
wrote:

>Ike Naar wrote:
>> On 2012-02-25, Shao Miller <sha0.miller@gmail.com> wrote:
>> > On 2/21/2012 23:28, Kaz Kylheku wrote:
>> >>    putchar('x') + putchar('x');
>> > 
>> > Doesn't that output a "bold 'x'" if they are evaluated
>> > simultaneously?

This is a joke.

>> 
>> Doesn't 6.5.2.2 p 10 forbid simultaneous evaluation?

This also is a joke.
>
>Doesn't anybody here understand a joke?

Is this a joke?

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


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

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


csiph-web