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


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

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-10 12:23 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<4F355285.5050901@verizon.net>
In reply to#17058
On 02/10/2012 11:35 AM, Kenneth Brody wrote:
...
> Pre-ansi days were certainly "fun" (FSVO).
...
> 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?)

No. It's not even required that different data types for the same
implementation use the bits in the same order on all types. Unsigned
char could use 1 ... 8, unsigned short could use 16 ... 1, unsigned
could use 1 32 2 31 ... 15 16, etc. I can't imagine any hardware being
built in a way that would make that a reasonable way to implement C, but
such an implementation could be conforming.

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


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

Fromfalk@rahul.net (Edward A. Falk)
Date2012-02-08 20:40 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<jgumk4$t33$2@blue-new.rahul.net>
In reply to#16868
In article <4f319955.234650417@text.giganews.com>,
Richard Harter <cri@tiac.net> wrote:
>
>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.

Perhaps, but it can still have a lot to do with optimization.

Consider:

  b = (sqrt(sin(x)*cos(x))) * a;

If the compiler can guess that a is very likely to be zero, and that the
left side is very likely to be expensive, and has no side effects, then
it can generate code that evaluates a first, and then decides whether
or not to evaluate the left side.

I realize that this is a contrived example, but the bottom line is
that C was intended to be a *fast* language, and not a *safe* language.
Why nail the compiler's foot to the floor if you don't have to.

(When I first heard about the C language, it was described to me
as a substitute for assembly language.  I think that's the proper
attitude to take when deciding between fast and pedantic.)

-- 
	-Ed Falk, falk@despams.r.us.com
	http://thespamdiaries.blogspot.com/

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


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

FromKeith Thompson <kst-u@mib.org>
Date2012-02-08 15:00 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<ln62fhlymb.fsf@nuthaus.mib.org>
In reply to#16943
falk@rahul.net (Edward A. Falk) writes:
> In article <4f319955.234650417@text.giganews.com>,
> Richard Harter <cri@tiac.net> wrote:
>>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.
>
> Perhaps, but it can still have a lot to do with optimization.
>
> Consider:
>
>   b = (sqrt(sin(x)*cos(x))) * a;
>
> If the compiler can guess that a is very likely to be zero, and that the
> left side is very likely to be expensive, and has no side effects, then
> it can generate code that evaluates a first, and then decides whether
> or not to evaluate the left side.
>
> I realize that this is a contrived example, but the bottom line is
> that C was intended to be a *fast* language, and not a *safe* language.
> Why nail the compiler's foot to the floor if you don't have to.

One problem with that contrived example is that the sqrt(), sin(), and
cos() functions can have the side effect of updating errno (if
math_errhandling & MATH_ERRNO is nonzero).

> (When I first heard about the C language, it was described to me
> as a substitute for assembly language.  I think that's the proper
> attitude to take when deciding between fast and pedantic.)

I don't disagree.  But there's a common misconception that C *is* an
assembly language (its' been called a "high-level assembler).  The key
difference is that an assembly language program specifies CPU
instructions, while a C program specifies behavior.

-- 
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]


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-09 01:10 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208170521.509@kylheku.com>
In reply to#16943
On 2012-02-08, Edward A. Falk <falk@rahul.net> wrote:
> In article <4f319955.234650417@text.giganews.com>,
> Richard Harter <cri@tiac.net> wrote:
>>
>>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.
>
> Perhaps, but it can still have a lot to do with optimization.
>
> Consider:
>
>   b = (sqrt(sin(x)*cos(x))) * a;
>
> If the compiler can guess that a is very likely to be zero, and that the
> left side is very likely to be expensive, and has no side effects, then
> it can generate code that evaluates a first, and then decides whether
> or not to evaluate the left side.

Since a is not volatile and those transcendental functions have no side
effects, this evaluation order would be allowed even if the evaluation order
for A * B is that A is evaluated first.

Why don't we change this to:

  b = sqrt(sin(x)*cos(x)) && a;

Or how about:

  b = sqrt(sin(x)*cos(x)), a;

Both && and , have ordering properties today.

If a is zero, do you believe that the trigonometry has to be evaluated?

> I realize that this is a contrived example, but the bottom line is
> that C was intended to be a *fast* language, and not a *safe* language.

Fast to implement, sure.

> Why nail the compiler's foot to the floor if you don't have to.

So that you don't shoot through yours.

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


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

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-02-09 20:43 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<8727249.257.1328849036072.JavaMail.geo-discussion-forums@pbbpm6>
In reply to#16957
在 2012年2月9日星期四UTC+8上午9时10分29秒,Kaz Kylheku写道:
> On 2012-02-08, Edward A. Falk <falk@rahul.net> wrote:
> > In article <4f319955.234650417@text.giganews.com>,
> > Richard Harter <cri@tiac.net> wrote:
> >>
> >>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.
> >
> > Perhaps, but it can still have a lot to do with optimization.
> >
> > Consider:
> >
> >   b = (sqrt(sin(x)*cos(x))) * a;
> >
> > If the compiler can guess that a is very likely to be zero, and that the
> > left side is very likely to be expensive, and has no side effects, then
> > it can generate code that evaluates a first, and then decides whether
> > or not to evaluate the left side.
> 
> Since a is not volatile and those transcendental functions have no side
> effects, this evaluation order would be allowed even if the evaluation order
> for A * B is that A is evaluated first.
> 
> Why don't we change this to:
> 
>   b = sqrt(sin(x)*cos(x)) && a;
> 
> Or how about:
> 
>   b = sqrt(sin(x)*cos(x)), a;
> 
> Both && and , have ordering properties today.
> 
> If a is zero, do you believe that the trigonometry has to be evaluated?
> 

sqrt(sin(x)*cos(x))=sqrt(sin(x*2)*0.5)

Even the sqrt function call can be simplified by a numerical 
analysis, but this is not the language or compiler's job now. 

Thus, it is time to distinguish different programming tools 
for different jobs in different applications. 

I don't believe that one computer language can solve all kinds of 
tasks as a religeion proposed by some authors. 

> > I realize that this is a contrived example, but the bottom line is
> > that C was intended to be a *fast* language, and not a *safe* language.
> 
> Fast to implement, sure.
> 
> > Why nail the compiler's foot to the floor if you don't have to.
> 
> So that you don't shoot through yours.

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


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

FromRobert Wessel <robertwessel2@yahoo.com>
Date2012-02-09 23:36 -0600
SubjectRe: what is the right value about a = a++;
Message-ID<r5a9j7pc4pm0emc8t0kkmo6hcp2ejpjl9b@4ax.com>
In reply to#17034
On Thu, 9 Feb 2012 20:43:56 -0800 (PST), 88888 Dihedral
<dihedral88888@googlemail.com> wrote:

>? 2012?2?9????UTC+8??9?10?29??Kaz Kylheku???
>> On 2012-02-08, Edward A. Falk <falk@rahul.net> wrote:
>> > In article <4f319955.234650417@text.giganews.com>,
>> > Richard Harter <cri@tiac.net> wrote:
>> >>
>> >>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.
>> >
>> > Perhaps, but it can still have a lot to do with optimization.
>> >
>> > Consider:
>> >
>> >   b = (sqrt(sin(x)*cos(x))) * a;
>> >
>> > If the compiler can guess that a is very likely to be zero, and that the
>> > left side is very likely to be expensive, and has no side effects, then
>> > it can generate code that evaluates a first, and then decides whether
>> > or not to evaluate the left side.
>> 
>> Since a is not volatile and those transcendental functions have no side
>> effects, this evaluation order would be allowed even if the evaluation order
>> for A * B is that A is evaluated first.
>> 
>> Why don't we change this to:
>> 
>>   b = sqrt(sin(x)*cos(x)) && a;
>> 
>> Or how about:
>> 
>>   b = sqrt(sin(x)*cos(x)), a;
>> 
>> Both && and , have ordering properties today.
>> 
>> If a is zero, do you believe that the trigonometry has to be evaluated?
>> 
>
>sqrt(sin(x)*cos(x))=sqrt(sin(x*2)*0.5)
>
>Even the sqrt function call can be simplified by a numerical 
>analysis, but this is not the language or compiler's job now. 
>
>Thus, it is time to distinguish different programming tools 
>for different jobs in different applications. 
>
>I don't believe that one computer language can solve all kinds of 
>tasks as a religeion proposed by some authors. 


For this particular case, why not?  I mean, we all expect a compiler
to (usually) evaluate a=b*2 as a=b+b.  Where do you think the limit
should be?  Why not expect a compiler to go so far as to evaluate that
as an appropriate range reduction followed by the very tractable
Taylor series* for sqrt(sin(x*2)*0.5)?  While I suspect most C users
would not get too excited about that, a bunch of HPC folks might - so
perhaps that optimization might be more likely in a Fortran compiler,
and putting a symbolic differentiation engine in the compiler might be
a bit extreme, but still, what's the limit?


*if we must:  x**(1/2) - (x**(5/2) / 3) + (x**(9/2) / 90) - (x**(13/2)
/ 378)...

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


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

Fromcri@tiac.net (Richard Harter)
Date2012-02-10 02:40 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<4f3481ce.425243016@text.giganews.com>
In reply to#16943
On Wed, 8 Feb 2012 20:40:36 +0000 (UTC), falk@rahul.net (Edward A.
Falk) wrote:

>In article <4f319955.234650417@text.giganews.com>,
>Richard Harter <cri@tiac.net> wrote:
[snip]
>
>I realize that this is a contrived example, but the bottom line is
>that C was intended to be a *fast* language, and not a *safe* language.
>Why nail the compiler's foot to the floor if you don't have to.

Well, no, C was intended as a convenient portable replacement for
assembly language in systems programming.  Safe and fast are not
opposites.

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


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

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-09 23:17 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jh25pd$57h$1@dont-email.me>
In reply to#17027
On 02/09/2012 09:40 PM, Richard Harter wrote:
> On Wed, 8 Feb 2012 20:40:36 +0000 (UTC), falk@rahul.net (Edward A.
> Falk) wrote:
...
> Well, no, C was intended as a convenient portable replacement for
> assembly language in systems programming.  Safe and fast are not
> opposites.

Nor are they they same; as with any two characteristics that aren't
highly correlated, you can and often do have trade-offs between them.
-- 
James Kuyper

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-08 23:49 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208154210.742@kylheku.com>
In reply to#16868
On 2012-02-07, Richard Harter <cri@tiac.net> 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.

Exactly! Evaluation order could not have been standardized at the time
C was standardized for the first time, simply because it would have required
most compilers to change something. This is not the proper business of
a standard (to invent new stuff, that is). The proper business is to
identify the commonality in what is out there and codify it.

But, evidently, it IS now the business of C standardization to invent new crud.
So why don't they put a priority on tying loose ends left over from
the 1980's?

Before they started introducing crud like variable length arrays, they should
have revisited the behaviors that could not have been pinned down in 1989, and
tightened them up.

The problem is, I suspect, that some people have their egos invested in this
idiotic sequence point stuff. To throw it out the window would be a huge
backpedaling.  In C99 they just about nearly put out an new informative annex
which introduced a formal model of sequence points, which polished this turd
into a foot-deep shine.

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-08 23:42 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208153507.279@kylheku.com>
In reply to#16862
On 2012-02-07, 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?

I do not believe that this is where "C's optimization abilities" come from
at all.

(Many of the optimization abilities of some early compilers from circa 1980
may have come from that, however.)

Do not forget the "as if" principle. I would want the above in the abstract
semantics, not in the actual semantics, of course.

Remember, C already has some constraints on evaluation order, like sequence
points between statements. Do you believe that sequential statements defeat
optimization?  Do you think that i++; i++ is slower than i += 2 because
it calls for i to be updated twice? (Assume non-volatile-qualified i.)

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


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

Fromblp@cs.stanford.edu (Ben Pfaff)
Date2012-02-07 12:09 -0800
SubjectRe: what is the right value about a = a++;
Message-ID<87ipjiz9qv.fsf@blp.benpfaff.org>
In reply to#16825
Kaz Kylheku <kaz@kylheku.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.

You could use Java.
-- 
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}

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


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

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-07 07:42 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jgr68b$463$1@dont-email.me>
In reply to#16809
On 02/06/2012 05:33 AM, lujnan 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.

Because they don't want you to write code like this. It serves no useful
purpose to write code this way. I can think of two plausible defined
behaviors for a=a++. One is equivalent to a++, so why bother with the
"a="? The other is equivalent to a = a, so why bother writing anything
at all?

The rule violated by this code is much more general than that, and
includes cases that cannot be so easily dismissed. But it is almost
always the case that the intended behavior of any code violating that
rule can be more clearly expressed by separating it into two or more
separate statements, none of which violate that rule.
-- 
James Kuyper

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-07 17:21 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120207090547.24@kylheku.com>
In reply to#16833
On 2012-02-07, James Kuyper <jameskuyper@verizon.net> wrote:
> On 02/06/2012 05:33 AM, lujnan 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.
>
> Because they don't want you to write code like this. It serves no useful
> purpose to write code this way.

That particular instance (a = a++) serves no useful purpose. The instance
does not damn the class.

Does it serve no purpose that if I have f(..., g(), ... h()); I can
be assured that g is called before h?

Etc.

Even if a = a++ serves no useful purpose, suppose that I'm managing a
software project and someone writes that somewhere (not me, I wouldn't).
It sure would help me if a = a++ were to be reliable and compute the same
thing regardless of compiler, optimization setting or target.


> I can think of two plausible defined
> behaviors for a=a++. One is equivalent to a++, so why bother with the
> "a="? The other is equivalent to a = a, so why bother writing anything
> at all?

One particular choice of behavior stands out: the simple, recursive rule:

- evaluate each subexpression completely, includiing all of its side effects,
  before evaluating the parent expression.

- if an expression has several subexpressions, evaluate them left to right.

> But it is almost
> always the case that the intended behavior of any code violating that
> rule can be more clearly expressed by separating it into two or more
> separate statements, none of which violate that rule.

That's obviously only if you know what the behavior should be.

That's easy; just find out the whereabouts of the guy who wrote it
three years ago who no longer works here ...

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


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

FromStephen Sprunk <stephen@sprunk.org>
Date2012-02-07 15:24 -0600
SubjectRe: what is the right value about a = a++;
Message-ID<jgs4ph$7r4$1@dont-email.me>
In reply to#16846
On 07-Feb-12 11:21, Kaz Kylheku wrote:
> On 2012-02-07, James Kuyper <jameskuyper@verizon.net> wrote:
>> I can think of two plausible defined
>> behaviors for a=a++. One is equivalent to a++, so why bother with the
>> "a="? The other is equivalent to a = a, so why bother writing anything
>> at all?
> 
> One particular choice of behavior stands out: the simple, recursive rule:
> 
> - evaluate each subexpression completely, includiing all of its side effects,
>   before evaluating the parent expression.
> 
> - if an expression has several subexpressions, evaluate them left to right.

Nice of you to dictate that people using systems that more efficiently
evaluate sub-expressions from right to left should suffer performance
degradation of all code, even in the majority of cases where the code is
well-written and therefore the order doesn't actually matter, simply
because it doesn't suit your sensibilities.

If you /need/ to know that "foo(bar(), baz());" calls bar() before
baz(), then just write "tmp=bar(); foo(tmp, baz());".  There is no need
to suffer that performance penalty, though, in the vast majority of
cases where it _doesn't_ matter.

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]


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-09 01:27 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208171952.534@kylheku.com>
In reply to#16865
On 2012-02-07, Stephen Sprunk <stephen@sprunk.org> wrote:
> On 07-Feb-12 11:21, Kaz Kylheku wrote:
>> On 2012-02-07, James Kuyper <jameskuyper@verizon.net> wrote:
>>> I can think of two plausible defined
>>> behaviors for a=a++. One is equivalent to a++, so why bother with the
>>> "a="? The other is equivalent to a = a, so why bother writing anything
>>> at all?
>> 
>> One particular choice of behavior stands out: the simple, recursive rule:
>> 
>> - evaluate each subexpression completely, includiing all of its side effects,
>>   before evaluating the parent expression.
>> 
>> - if an expression has several subexpressions, evaluate them left to right.
>
> Nice of you to dictate that people using systems that more efficiently
> evaluate sub-expressions from right to left should suffer performance
> degradation of all code, even in the majority of cases where the code is

Proof?

> well-written and therefore the order doesn't actually matter, simply
> because it doesn't suit your sensibilities.

In the majority of cases, C code is not well-written. The history of C
programming at large is riddled with crashing applications and operating
systems, and exploitable security holes in online systems.

> If you /need/ to know that "foo(bar(), baz());" calls bar() before
> baz(), then just write "tmp=bar(); foo(tmp, baz());".  There is no need

Thanks for the clueful suggestion, but, see, what I need to know first is
WHERE this is hiding in a large code base.

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


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

FromStephen Sprunk <stephen@sprunk.org>
Date2012-02-10 21:57 -0600
SubjectRe: what is the right value about a = a++;
Message-ID<jh4ouk$i5q$1@dont-email.me>
In reply to#16958
On 08-Feb-12 19:27, Kaz Kylheku wrote:
> On 2012-02-07, Stephen Sprunk <stephen@sprunk.org> wrote:
>> On 07-Feb-12 11:21, Kaz Kylheku wrote:
>>> - if an expression has several subexpressions, evaluate them left to right.
>>
>> Nice of you to dictate that people using systems that more efficiently
>> evaluate sub-expressions from right to left should suffer performance
>> degradation of all code, even in the majority of cases where the code is
> 
> Proof?

I've already provided one example.

>> well-written and therefore the order doesn't actually matter, simply
>> because it doesn't suit your sensibilities.
> 
> In the majority of cases, C code is not well-written. The history of C
> programming at large is riddled with crashing applications and operating
> systems, and exploitable security holes in online systems.

I disagree, but perhaps my perspective is limited by where I've worked.

>> If you /need/ to know that "foo(bar(), baz());" calls bar() before
>> baz(), then just write "tmp=bar(); foo(tmp, baz());".  There is no need
> 
> Thanks for the clueful suggestion, but, see, what I need to know first is
> WHERE this is hiding in a large code base.

I agree.  If C had a way to mark functions const/pure (as C++ does),
then it would be easy for compilers to flag a warning in cases where
unspecified order of evaluation might cause a problem; however, without
that ability, there would be far too many false positives for such a
warning to be useful.

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]


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

From"Joel C. Salomon" <joelcsalomon@gmail.com>
Date2012-02-08 01:00 -0500
SubjectRe: what is the right value about a = a++;
Message-ID<jgt32c$2sv$1@news.albasani.net>
In reply to#16809
On 02/06/2012 05:33 AM, lujnan wrote:
> maybe it shows the c world is not perfect. in this point i like the
> define of java.

If you want Java, you know where to find it.

--Joel

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


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

Fromfalk@rahul.net (Edward A. Falk)
Date2012-02-08 20:33 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<jgum5v$t33$1@blue-new.rahul.net>
In reply to#16809
In article <bf40ad26-3199-441e-a524-acf38177273f@og8g2000pbb.googlegroups.com>,
lujnan  <lujnan@gmail.com> wrote:
>Why C Standards Committee does not constrain this case.

Because it's a dumb case.  You're not supposed to write that idiom,
and pointless constraints are a bad thing in a system where performance
is king.

-- 
	-Ed Falk, falk@despams.r.us.com
	http://thespamdiaries.blogspot.com/

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


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

FromKaz Kylheku <kaz@kylheku.com>
Date2012-02-09 02:05 +0000
SubjectRe: what is the right value about a = a++;
Message-ID<20120208172803.616@kylheku.com>
In reply to#16941
On 2012-02-08, Edward A. Falk <falk@rahul.net> wrote:
> In article <bf40ad26-3199-441e-a524-acf38177273f@og8g2000pbb.googlegroups.com>,
> lujnan  <lujnan@gmail.com> wrote:
>>Why C Standards Committee does not constrain this case.
>
> Because it's a dumb case.  You're not supposed to write that idiom,

You're only not "supposed" to write that only because the behavior isn't
standardized, so this is circular reasoning.

You were also not supposed to write this, prior to 1999:

  struct foo x = { .member = 42 };

nor this:

  { int x[var]; }

C programmers obviously sometimes do what they are not supposed to, otherwise
we would not need outfits like the Computer Emergency Response Team (CERT).

You may be a perfect C programmer who never does what isn't supposed
to be done, but that's a sample of one, and highly biased. 

I'm not such a programmer. All I can say is that I have never knowingly
broken the rules.  I do not buy arguments that "I have never needed that
behavior to be well-defined" or "I have never made such mistakes".

I do not buy the argument that the language should be unsafe, and programming
should be done only by those who can avoid stepping on the mines.  On a
project, it's good to have one such savant, but not the whole team.

Why should only programming language users be careful and responsible, but not
language designers?

> and pointless constraints are a bad thing in a system where performance
> is king.

The constraint only affects situations where expressions have interacting side
effects. All other code has the same meaning as without the constraints.

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


#16968

FromMarkus Wichmann <nullplan@gmx.net>
Date2012-02-09 09:28 +0100
Message-ID<0mcc09-s63.ln1@voyager.wichi.de.vu>
In reply to#16808
On 06.02.2012 10:45, bert 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.

On a related note, what about the following:

static int foo;
static int bar(void)
{
    return foo++;
}

int main(void)
{
    return foo++ - bar();
}

The standard sticks a sequence point between the evaluation of a
function call's arguments but not after its return. bar() is not
guarenteed to be called before or after evaluation of foo++, so bar()
can have different results. So does the above program exhibit UB?

Because if it does, that means that no-one should use function calls in
compound expressions. Unless the function called is pure or there's only
one function call which is compounded only with local variables (i.e.
variables with a scope smaller than file scope).

Ciao,
Markus

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


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

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


csiph-web