| |

VerySource

 Forgot password?
 Register
Search
Author: mpc_bywind

Discuss a C language problem

[Copy link]

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-1-26 06:09:01
| Show all posts
What compiler is used?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-26 16:54:01
| Show all posts
This is related to the compiler
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-26 20:18:01
| Show all posts
It should be the language standard. Among the language option keywords in the assembly, the C and STDCALL keywords are pushed in the process parameters in reverse order, and the PASCAL keyword is pushed in the parameters in the forward order.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

Post time: 2020-1-27 16:45:01
| Show all posts
Give you a suggestion,
If not sure. Just use i. And then write a line ++

a = i;
i ++;

I don't really know how big the gap is after compilation, especially the compiler optimization is still very powerful.
Even if there is a gap, it is not very special and has no effect. Wait until the program is fine and optimize it.
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-27 19:36:02
| Show all posts
Everyone upstairs said that.
This is compiler related. It is recommended not to use this when programming. I can't figure out what went wrong.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 05:36:01
| Show all posts
My understanding, printf shows the value of the variable after executing this statement, so it is easy to understand
printf ("% d,% d", i, i ++); // This situation is shown as: 3,2-at the beginning i = 2, after executing this statement, i = 3 because of i ++, but The value of i ++ expression is still 2

printf ("% d,% d", i, ++ i); // This case is displayed as: 3,3-After executing this statement i = 3, (++ i) = 3
The explanation of the last two sentences is similar to the previous two sentences, and the result is no problem.
printf ("% d,% d", i ++, i); // This case is displayed as: 2,3
printf ("% d,% d", ++ i, i); // This case is displayed as: 3,3
Reply

Use magic Report

0

Threads

17

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 Invalid IP Address

Post time: 2020-1-30 00:45:02
| Show all posts
Someone has said upstairs that when calling functions, the C language standard does not specify the order of parameter calculation. Please do not write such code. Different compilers will behave differently.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-1 12:27:01
| Show all posts
The compiler scans from right to left, setting i = 5
printf ("% d,% d", i, i ++); // 6,5
printf ("% d,% d", i, ++ i); // 6,6,
printf ("% d,% d", i ++, i); // 5,5
printf ("% d,% d", ++ i, i); // 6,5
Reply

Use magic Report

0

Threads

16

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-2-1 18:00:01
| Show all posts
The key is to execute from right to left
There is auto-increment before and after use.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-12 09:45:02
| Show all posts
If you don't consider the other behaviors of the compiler, only consider pushing the stack from right to left. . .

printf ("% d,% d", i, i ++); // 3,2
printf ("% d,% d", i, ++ i); // 3,3,
printf ("% d,% d", i ++, i); // 2,2
printf ("% d,% d", ++ i, i); // 3,2

But the actual situation will vary depending on the behavior of the compiler, so this form is uncertain.

Remember this in effect c ++. . .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list