This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Handling pre-increment and post-increment in GCC
- From: Andrew Haley <aph at redhat dot com>
- To: "Manjunath B S" <manjunathbs at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 19 Oct 2006 11:51:24 +0100
- Subject: Re: Handling pre-increment and post-increment in GCC
- References: <8731bc0e0610190331qb948c90vcc780be78e563ce2@mail.gmail.com> <8731bc0e0610190337y3569ddcfo7e5afcc6c8567a09@mail.gmail.com>
Manjunath B S writes:
> I am trying to understand how GCC handles this piece of code, but
> unfortunately the behaviour is different on different architectures
> =====================================================
> #include < stdio.h>
>
> int main(void)
> {
> int i = 2;
>
> return printf("Post increment : %d, Pre increment : %d\n", i++, ++i);
> }
> =====================================================
>
> On Powerpc (Powerbook G4) this gives
> %%%%%%%%%%%%%%%%%%%
> Post increment : 2, Pre increment : 4
>
> however on Intel machines this gives
> %%%%%%%%%%%%%%%%%%%
> Post increment : 4, Pre increment : 2
>
> On MIPS & ARM, the behaviour is different as well.
>
> Can anyone please explain the same?? Also can anyone please point me
> the direction where I should look in the GCC Internals for a clear
> understanding??
It doesn't matter, because Your code is undefined on any C compiler on
any machine. See C99, Section 6.5 Para. 2.
Andrew.