#include<stdio.h>
int main(void)
{
static int i=i++, j=j++, k=k++;
printf("i = %d j = %d k = %d", i, j, k);
return 0;
}
Output in Turbo C 4.5 :
i = 0 j = 0 k = 0
In gcc I'm getting the error:
Initializer element is not constant
Which one is logically correct ? I'm in bit confusion..
Standard says about initialization (6.7.8):
4 All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.
(That's from C99, but C89 says almost exactly the same thing.)
So it looks as though GCC is more correct than 15-year old abandonware. (Who'd a thunk it?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With