Timeline for Simple calculator in C
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 26, 2015 at 10:13 | comment | added | tomsmeding |
Moving the variables and function call into the printf statement might improve performance, but if you optimise sensibly, like you should at all times do, (-O2 ), the compiler will almost certainly do that for you. If using the variables is clearer, use them. I'm not certain about the printf call chaining, you might reduce the number of instructions that way, but I've seen with my own eyes the printf -> puts conversion happening. This post depends on that sole fact.
|
|
May 25, 2015 at 22:45 | vote | accept | Daniel Morris | ||
May 25, 2015 at 22:21 | comment | added | glampert | I think the terms you are looking for about the first item would be separation of concerns or single responsibility. A function is better if doing one thing only, e.g.: one gets the user input, the other processes it. | |
May 25, 2015 at 21:58 | history | edited | SirPython | CC BY-SA 3.0 |
added 4 characters in body
|
May 25, 2015 at 21:57 | comment | added | SirPython |
I believe so, as by putting the return value of addition in to result and then using result in printf , you are making 2 memory interactions. However, if you just put addition(num1, num2) in the printf call, you are making 0 memory interactions.
|
|
May 25, 2015 at 21:45 | comment | added | Ishaan |
I agree with your function definition. However, would it not be better to not declare result and instead replace the variable with `addition(num1, num2) in the printf-statement?
|
|
May 25, 2015 at 21:38 | vote | accept | Daniel Morris | ||
May 25, 2015 at 21:38 | |||||
May 25, 2015 at 21:07 | history | answered | SirPython | CC BY-SA 3.0 |