RE: w3c-libwww-5.2.8-7 bug report

Hmmm...  Curious...  Try this:

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
  int i;
  int m;
  int n;

  i = 0;
  i = i++;
  printf("i = 0, i = i++, i => %d\n", i);

  i = 0;
  i = ++i;
  printf("i = 0, i = ++i, i => %d\n", i);

  i = 0;
  n = ++i;

  printf("i = 0, n = ++i, n => %d\n", n);

  i = 0;
  m = i++;
  printf("i = 0, m = i++, m => %d\n", m);

  exit(0);
}

-----Original Message-----
From: Joe Konczal [mailto:joe.konczal@nist.gov]
Sent: Wednesday, January 30, 2002 12:08 PM
To: Jean-Christophe Touvet
Cc: Desrochers, Gary; Manuele Kirsch Pinheiro; Rob Corell; David
Binderman; www-lib@w3.org
Subject: Re: w3c-libwww-5.2.8-7 bug report


Jean-Christophe Touvet wrote:

>>Hmmm... Don't want to get into a long drawn out discussion on this but
>>I don't get why you "concluded" that "i = ++i;" is undefined in K&R "C".
>>I have the Kernighan an Ritchie book sitting in front of me and it does
>>describe what would happen with the expression "x = ++i;" and "x =
>>i++;".
>>
>
> And what about "i = i++;" ?
>
> Would you increment "i" before or after the assignment ?
>
>    -JCT-
>
>
After, of course.  But the result would be the same as incrementing it 
before.  There is only one "i" and it gets incremented either way.  Try 
this little program, and let me know if you find any implementation of C 
where the value of "i" is not one in both cases.

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
  int i;

  i = 0;
  i = i++;
  printf("i = 0, i = i++, i => %d\n", i);

  i = 0;
  i = ++i;
  printf("i = 0, i = ++i, i => %d\n", i);

  exit(0);
}

Received on Wednesday, 30 January 2002 15:04:21 UTC