我看到有人寫代碼以這種方式:嵌套函數及其用處,函數調用一個又一個?
void function2()
{.....
..more blah blah...
.<I think i will stop nesting my function here>...
..blah blah. over and out....
}
void function1()
{.....
..blah blah...
function2();
....
}
void LCD_disp_main()
{
<automatic, static... variable declaration>
....
function1(); //calling a function 1
.....
}
,而不是寫,你通常會放在函數的定義,並把它內嵌在這裏。
void LCD_disp_main()
{
<automatic, static... variable declaration>
....
<function1() and function2();> //instead of calling function1 and fucntion2 just inline it here.
.....
}
一個優於另一個的好處是什麼? 第一組不會使堆棧在每次調用新函數時都保持增長,儘管它會在選項2中增長相同的安裝量?上下文切換?
一些研究產生了這個,[鏈接](https://www.quora.com/Whats-the-most-important-lesson-youve-learned-as-a-software-engineer) – newb7777
@ newb7777第一個答案在你的鏈接中說肯·湯普森不得不說。我認爲這足以讓一般的人類看到的優點:) – babon