Sunday, November 16, 2014

Inline Functions versus Macros

add my commend into the content

  1. Inline functions follow all the protocols of type safety enforced on normal functions.
    • more safe then the macro, especially, for the type defination.
    • for the type check, macro is checked by prepocessor, and inline functions is checked by compilar.
  2. Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
    • only difference is keyword “inline”
  3. Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.
    • more variable for arguments
  4. There is no risk if called multiple times. But there is risk in macros which can be dangerous when the argument is an expression.
  5. functions can include multiple lines of code without trailing backlashes.
  6. functions have thier own scope for variables and they can return a value.
  7. debuging

Reference

[1] http://msdn.microsoft.com/en-us/library/bf6bf4cf.aspx

[2] http://www.thegeekstuff.com/2013/04/c-macros-inline-functions/

No comments:

Post a Comment

Register Transfer Level Design with Verilog (1) [ebook]

設計程式之所以有趣不外乎是它的千變萬化,同樣的結果卻有不同的寫法。 但這些不同寫法當中也並沒有分誰對誰錯,也沒有制定標準來規範何事該用何解。 這也就是我們設計者的珍貴!! [1] Primitive Instantiations 在Verilog中最基本的邏輯...