This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: increasing var twice in a statement


Hi,

2007/6/15, Willi Mann <willi@wm1.at>:
Hi!

Can anybody tell me what output the following program snippet should
produce according to C standard:

int main(void) {
        int a;
        int b;
        b = 3;
        a = ++b + ++b;
        printf("%d\n",a);
        return 0;
}

I would have expected 9, but gcc 4.1.2 produced a binary that wrote 10.

Willi

Please CC: me in replys, I'm not on the list.


try it: a = (b=b+1) + (b=b+1);

This is ugly! hehehe

I'm doing crazy!

Alan


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