the ++ operator
Sidirourgos Lefteris
lsidir at ics.forth.gr
Fri Nov 21 15:27:32 EET 2003
Ioannis Papaioannou wrote:
> Steve Stavropoulos wrote:
>
>> On Thu, 20 Nov 2003, Vasilis Vasaitis wrote:
>
> [snip]
>
>>> c = a[i] + b[i++];
>>
> [snip]
>
>>> έχουν undefined behaviour, όπως λέμε, δηλαδή ο compiler κάνει ό,τι
>>> γουστάρει, οπότε δε βασιζόμαστε και τις γράφουμε κάπως αλλιώς.
>>
>>
>> La8os! O compiler symfwna me thn ansi c exei _plhrws_ defined
>> symperifora otan blepei to ++ ws prefix h postfix. Otan einai prefix
>> tote to increment 8a ginei PRIN to evaluation ths ypoloiphs protashs,
>> enw otan einai postfix tote to increment 8a ginei META to evaluation
>> ths ypoloiphs protashs.
>
>
> Symfwna me thn ansi c kai to manual pou diabases, mporeis na
> apanthseis me sigouria sto parakatw (gia olous tous ansi c compilers)?
>
> H ekfrash gia i = 0:
> c = a[i]+b[i++] + a[i]+b[i];
>
> antistoixei me poio apo ta parakatw:
> 1) c = a[0] + b[1] + a[0] + b[0];
> 2) c = a[0] + b[1] + a[1] + b[1];
> 3) c = a[1] + b[1] + a[0] + b[0];
> 4) c = a[1] + b[1] + a[1] + b[1];
Oxi akribws:) to b[1] ths deyterhs sthlhs sto paradeigma sou, 8a einai
panta b[0]. Mhn 3exnas oti to ++ meta to telesth (i++) ay3anei ton
telesth meta thn xrhsh toy, ena to ++ prin to telesth (++i) ton ay3anei
prin thn xrhsh toy. Genika h parastash c = a[i]+b[i++] + a[i]+b[i];
mporei na bgalei 2^3 diaforetika apotelesmata!
lefteris
>
>
More information about the Linux-greek-users
mailing list