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


Groups > comp.lang.c > #20420

Re: pointer arithmetic question.

Message-ID <4FA67433.60EC@mindspring.com> (permalink)
Date 2012-05-06 08:53 -0400
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: pointer arithmetic question.
References <8d75171a-27cf-45ac-b9f4-57427d79b0d6@h4g2000pbe.googlegroups.com>

Show all headers | View raw


somenath wrote:
> 
> Hi All,
> 
> The following program is crashing.
 
>         char s[] ="test";
>         char *t=s;

>                  *t = toupper(*t++);
>                  //t++;

The comment is interesting 
because it shows
that you thought about doing it the right way.

> 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++);

No.

What is guaranteed, is that the side effects
from the evaluation of the arguments in a function call,
will be completed *before* the function call.

n1570
6.5.2.2 Function calls
Constraints

12 EXAMPLE In the function call
   (*pf[f1()]) (f2(), f3() + f4())
   the functions f1, f2, f3, and f4 may be called in any order.
   All side effects have to be completed before
   the function pointed to by pf[f1()] is called.

Do you have a copy of n1570?

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.

-- 
pete

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