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


Groups > comp.lang.c > #20552

Re: pointer arithmetic question.

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: pointer arithmetic question.
Date 2012-05-09 21:04 +0000
Organization Aioe.org NNTP Server
Message-ID <20120509134506.486@kylheku.com> (permalink)
References (1 earlier) <4FA67433.60EC@mindspring.com> <4FA8F6EC.52A3@mindspring.com> <kfnbolyx08z.fsf@x-alumni2.alumni.caltech.edu> <20120508061850.883@kylheku.com> <kfnwr4mziir.fsf@x-alumni2.alumni.caltech.edu>

Show all headers | View raw


On 2012-05-08, Tim Rentsch <txr@alumni.caltech.edu> wrote:
> Kaz Kylheku <kaz@kylheku.com> writes:
>
>> On 2012-05-08, Tim Rentsch <txr@alumni.caltech.edu> wrote:
>>> pete <pfiland@mindspring.com> writes:
>>>
>>>> pete wrote:
>>>>> 
>>>>> somenath wrote:
>>>>> >
>>>>> > Hi All,
>>>>> >
>>>>> > The following program is crashing.
>>>>> 
>>>>> >         char s[] ="test";
>>>>> >         char *t=s;
>>>>> 
>>>>> >                  *t = toupper(*t++);
>>>>> >                  //t++;
>>>>
>>>>> > But how that can happen also ? As post increment operator's side
>>>>> > effect will be taking effect after the sequence point in this case
>>>>> > after execution of the code *t = toupper(*t++);
>>>>
>>>>> Also,
>>>>> for the above definition of (t),
>>>>> the opcode for this expression: (t++)
>>>>> may or may not be
>>>>> the same as the opcode for this expression: (++t, t-1).
>>>>> Whether the side effect takes place before
>>>>> or after the value of (t++)is determined,
>>>>> is up to the implementation.
>>>>
>>>> That's the old way.
>>>> In the new standard, 
>>>> there is a sequence point 
>>>> in the value of a postfix increment expression.
>>>>
>>>> n1570
>>>> 6.5.2.4 Postfix increment and decrement operators
>>>> 2   The value computation of the result is sequenced    
>>>>     before the side effect of updating the stored value of the operand.
>>>
>>> Not a sequence point but a sequenced-before relationship.  A
>>> sequenced-before relationship is less restrictive than a sequence
>>> point. 
>>
>> No it isn't.  It is exactly the same thing.
>
> No, they are different.  An example will illustrate.
>
> The semantics for assignment includes a sequenced-before
> relationship.  This relationship allows expressions like
>
>    i = a[i] = i+1;
>
> to have well-defined behavior, rather than being undefined
> behavior.

I'm a fundamentalist believer in the literal interpretation of
the value of an assignment expression being that of the left
operand after the assignment.  I.e. to me it means one of two things. 

1. The left operand has to be identified during the evaluation
   of the assignment expression. The side effect of updating
   that operand can happen later, but once the effective
   address of the operand is established, it does not change
   That is to say, evaluation of the assignment expression and all of its
   constitutents is complete before that expression yields a value, except
   possibly for delayed side effects. There should not be a
   (re-)evaluation of the raw expression a[i] at side effect time.

   A violation of this principle means that an expression's
   value is used, even though the expression has not been completely
   evaluated, or else that an expression which should be evaluated
   just once is being evaluated twice.

   The semantic description of assignment does not suggest that
   any part of the evaluation of the assignment may be delayed
   to the next sequence point, only the effect of updating the
   operand. Updating an operand is not the same thing as
   calculating an operand's effective address and then updating it.
   The object known as the operand is not known until the expression which
   designates it is calculated. There is no operand until then.

2. Or else "after the assignment" literally means after the complete
   assignment (side effect and all). This means that the expression's
   value is not available until the side effect completes.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

pointer arithmetic question. somenath <somenathpal@gmail.com> - 2012-05-05 21:46 -0700
  Re: pointer arithmetic question. Philip Lantz <prl@canterey.us> - 2012-05-05 23:25 -0700
    Re: pointer arithmetic question. Paul N <gw7rib@aol.com> - 2012-05-06 07:52 -0700
  Re: pointer arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-05-06 06:58 +0000
  Re: pointer arithmetic question. pete <pfiland@mindspring.com> - 2012-05-06 08:53 -0400
    Re: pointer arithmetic question. pete <pfiland@mindspring.com> - 2012-05-08 06:35 -0400
      Re: pointer arithmetic question. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-08 06:37 -0700
        Re: pointer arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-05-08 14:32 +0000
          Re: pointer arithmetic question. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-08 10:31 -0700
            Re: pointer arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-05-09 21:04 +0000
              Re: pointer arithmetic question. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-10 10:06 -0700
                Re: pointer arithmetic question. Kaz Kylheku <kaz@kylheku.com> - 2012-05-11 17:52 +0000
                Re: pointer arithmetic question. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-11 19:27 -0700

csiph-web