tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] semantic of postincrement


From: Dr.-Ing. Torsten Finke
Subject: [Tinycc-devel] semantic of postincrement
Date: Fri, 9 Oct 2009 15:08:30 +0200
User-agent: Mutt/1.5.16 (2007-06-09)

Dear TCC-Developers, 
 
running some tests on tcc-0.9.25 I found an interesting behaviour concerning
postincrement. 

Please consider the following little program: 

#--------------------------------------------------
#include <stdio.h>
int main()
{
    int i = 0, a[] = { -1, -1 };
    a[i++] = i; 
    printf("%d %d\n", a[0], a[1]);
    return 0;
}
#--------------------------------------------------

running it I expected the output to be: 

0 -1

but indeed it is:

1 -1

Trying to understand the ANSI-C Standard, the evaluation sequence of the
assignment statement should be:
1. evaluate right side (since assignment is right associative) -> i = 0
2. calculate indix to "a" -> 0
3. assign 0 to a[0]
4. increment i

Am I wrong? 

BTW: GCC, VC++, cc(HP-UX) do as I had expected; TCC and LCC do not, but do the
same. 


TCC seems to be very nice. Thanks for your great work. 


Best regards 


Torsten Finke



-- 

------------------------------------------------------------------------

Dr.-Ing. Torsten Finke                       Amtsgericht Essen HRB 11500
Ingenieurgemeinschaft IgH                    USt-Id.-Nr.: DE 174 626 722
Ges. für Ingenieurleistungen mbH             Geschäftsführung:
Heinz-Bäcker-Str. 34                         Dr.-Ing. S. Rotthäuser
D-45356 Essen                                Dr.-Ing. T. Finke
Tel.: +49 201 / 360-14-17                    Dr.-Ing. W. Hagemeister
Fax.: +49 201 / 360-14-14                    Tel.: +49 201 / 360-14-0
address@hidden                  http://www.igh-essen.com

------------------------------------------------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]