This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

undefined?



please try this program

#include <stdio.h>
void main() {
  int i = 2;
  printf("%d\n", i++ * i++); 
  printf("%d\n", i); 
}

I know that i++ * i++ is undefined, but afterwards the value of i
should still be defined ( I think) and equal to 4

but the behaviour in gcc-2.8.1 the behaviour is optimiser dependant.

% gcc x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
4
3
% gcc -O1 x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
4
4

Also, although there's is again undefined behaviour involved, I think it's
strange
that both print statements should give the same result, in the program below.

#include <stdio.h>
void main() {
  int b = 6;
  b+=b++;
  printf("%d\n",b);
  b=6;
  printf("%d\n",b += b++);
}

% gcc x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
7
12
% gcc -O2 x.c -o xx ; xx
x.c: In function `main':
x.c:2: warning: return type of `main' is not `int'
13
12


regards, Eiso.

--
 
                                _________
_______________________________/ Eiso AB \_________________________

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]