Where the C macros stored in memory and how does it consumes more memory compared to functions?

后端 未结 4 1054
孤城傲影
孤城傲影 2021-01-22 11:05

I searched in web where will be the C macros stored in memory and how does it consumes more memory compared to functions? Could not get any satisfying answer .Can anyone please

4条回答
  •  猫巷女王i
    2021-01-22 11:28

    "The reason that this usually takes up more memory is that it gets repeated every time the macro is used."

    With a modern compiler depending on the compile settings (FAST CODE/SMALL CODE) it may spot commonly used code and optimize it into a function (SMALL), or it may inline the code for speed (FAST).

    It isn't always the case that the code will always be bigger depends on how good your optimizer is and the compiler settings you use.

    Of course you could always use macros that call functions rather than contain large inline sections of code. That is totally down to your choice.

提交回复
热议问题