回複:回複:我用visual c++ 6.0: 對的.

回答: 我用visual c++ 6.0意味深長2004-06-29 10:13:28


let me try to elaborate what redpepper stated:

the result has to do with how arguments are passed to function. standard C func call pushes argusments from right to left (that's why printf can take variable number of args). So if you examine assembly code correspondin to the program, the order of operations is:

1) increment a ( ++a);
2) push a into stack; (value 11)
3) push a into stack ( a in 'a++'; so value 11)
4) increment a ( a++)
5) push the format string into stack
6) control pass to printf()
7) pop stack ( a couple of times)

compiler works this way will produce (a++=11 ++a=11) which I verified using gcc.

If args are pushed from left to right, I expect to see 'a++=10 ++a=12'.

所有跟帖: 

one more comment -clowhand- 給 clowhand 發送悄悄話 (274 bytes) () 06/29/2004 postreply 20:53:17

don't understand? -pleaseexp- 給 pleaseexp 發送悄悄話 (295 bytes) () 06/30/2004 postreply 08:01:28

回複:don't understand? -clowhand- 給 clowhand 發送悄悄話 (380 bytes) () 06/30/2004 postreply 19:49:17

totally confused -goingcraz- 給 goingcraz 發送悄悄話 (259 bytes) () 06/30/2004 postreply 08:58:40

3! anwsers. Avoid! -紅辣椒- 給 紅辣椒 發送悄悄話 (13 bytes) () 06/30/2004 postreply 17:23:18

能解釋嗎? -真糊塗啦啦...- 給 真糊塗啦啦... 發送悄悄話 (0 bytes) () 06/30/2004 postreply 19:38:44

回複:能解釋嗎? -紅辣椒- 給 紅辣椒 發送悄悄話 (317 bytes) () 06/30/2004 postreply 19:47:15

這樣看來,還是VC++合理些 -意味深長- 給 意味深長 發送悄悄話 (0 bytes) () 06/30/2004 postreply 19:46:01

Finally! got the answer, -fianlly- 給 fianlly 發送悄悄話 (81 bytes) () 07/01/2004 postreply 08:43:49

請您先登陸,再發跟帖!