Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what is the right value about a = a++;

Reply
Thread Tools

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

 
 
Phil Carmody
Guest
Posts: n/a
 
      02-24-2012
Kaz Kylheku <(E-Mail Removed)> writes:
> On 2012-02-21, Phil Carmody <(E-Mail Removed)> wrote:
> > Kaz Kylheku <(E-Mail Removed)> writes:
> >> On 2012-02-07, Keith Thompson <(E-Mail Removed)> wrote:
> >> > lujnan <(E-Mail Removed)> 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)
 
Reply With Quote
 
 
 
 
Shao Miller
Guest
Posts: n/a
 
      02-25-2012
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?
 
Reply With Quote
 
 
 
 
Ike Naar
Guest
Posts: n/a
 
      02-25-2012
On 2012-02-25, Shao Miller <(E-Mail Removed)> 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.
 
Reply With Quote
 
Philip Lantz
Guest
Posts: n/a
 
      02-25-2012
Ike Naar wrote:
> On 2012-02-25, Shao Miller <(E-Mail Removed)> 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?
 
Reply With Quote
 
lawrence.jones@siemens.com
Guest
Posts: n/a
 
      02-27-2012
Ike Naar <(E-Mail Removed)> wrote:
> On 2012-02-25, Shao Miller <(E-Mail Removed)> 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?


This started out as a joke, but there's an important point to be made
here. Note carefully 7.1.4p1:

Any function declared in a header may be additionally
implemented as a function-like macro defined in the header....
Any invocation of a library function that is implemented as a
macro shall expand to code that evaluates each of its arguments
exactly once, fully protected by parentheses where necessary, so
it is generally safe to use arbitrary expressions as
arguments.186)

186) Such macros might not contain the sequence points that the
corresponding function calls do.

So, although you're guaranteed that actual function calls aren't executed
simultaneously, there's no guarantee that library routines are actually
implemented as function calls unless you're careful to avoid any
potential macro version.
--
Larry Jones

Honey, are we out of aspirin again? -- Calvin's Dad
 
Reply With Quote
 
Ike Naar
Guest
Posts: n/a
 
      02-27-2012
On 2012-02-27, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> Ike Naar <(E-Mail Removed)> wrote:
>> On 2012-02-25, Shao Miller <(E-Mail Removed)> 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?

>
> This started out as a joke, but there's an important point to be made
> here. Note carefully 7.1.4p1:
>
> Any function declared in a header may be additionally
> implemented as a function-like macro defined in the header....
> Any invocation of a library function that is implemented as a
> macro shall expand to code that evaluates each of its arguments
> exactly once, fully protected by parentheses where necessary, so
> it is generally safe to use arbitrary expressions as
> arguments.186)
>
> 186) Such macros might not contain the sequence points that the
> corresponding function calls do.
>
> So, although you're guaranteed that actual function calls aren't executed
> simultaneously, there's no guarantee that library routines are actually
> implemented as function calls unless you're careful to avoid any
> potential macro version.


Would parenthesizing the function name, as in

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

be sufficient to make sure the non-macro verion is used?
 
Reply With Quote
 
Shao Miller
Guest
Posts: n/a
 
      02-27-2012
On 2/27/2012 17:42, Ike Naar wrote:
> On 2012-02-27, (E-Mail Removed)<lawrence.jones@siemens. com> wrote:
>> Ike Naar<(E-Mail Removed)> wrote:
>>> On 2012-02-25, Shao Miller<(E-Mail Removed)> 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?

>>
>> This started out as a joke, but there's an important point to be made
>> here. Note carefully 7.1.4p1:
>>
>> Any function declared in a header may be additionally
>> implemented as a function-like macro defined in the header....
>> Any invocation of a library function that is implemented as a
>> macro shall expand to code that evaluates each of its arguments
>> exactly once, fully protected by parentheses where necessary, so
>> it is generally safe to use arbitrary expressions as
>> arguments.186)
>>
>> 186) Such macros might not contain the sequence points that the
>> corresponding function calls do.
>>
>> So, although you're guaranteed that actual function calls aren't executed
>> simultaneously, there's no guarantee that library routines are actually
>> implemented as function calls unless you're careful to avoid any
>> potential macro version.

>
> Would parenthesizing the function name, as in
>
> (putchar)('x') + (putchar)('x');
>
> be sufficient to make sure the non-macro verion is used?


That's described in the same paragraph. Also described is #undef usage.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Menu Items is not right aligned with Right to Left documen =?Utf-8?B?QmlzaG95?= ASP .Net 0 12-28-2006 11:39 AM
Right-Click With Mouse and Toolba Buttonsr Don't Work Right Bigfoot It Is Computer Support 0 10-30-2006 06:08 PM
Tool to enable Right click on pages where Right click is disabled tsteinke@gmail.com Computer Support 4 08-28-2005 11:53 PM
Tool to right click image in windows explorer and rotate image right or left 90 degrees siliconpi Digital Photography 2 11-29-2004 12:56 PM
pass the right form input to the right control Tom ASP .Net 0 12-11-2003 03:07 AM



Advertisments