开发者

how does inline functions expose internal data structures?

I hear this a lot of times that: "inline functions in C expose internal data structures" and that is one of the reasons some people do not like them.

Can someone please explain, how?

Thanks in advance.

Lets say I have a program code.c and a function func(). I can 1) make func() inline - which will expose whatever I do with my data-structures in code.c 2) I can put func() in a l开发者_运维技巧ibrary and provide that as a shared lib (which is not readable - I guess ?? :p) ---- Is this a correct analysis?


Since you put inline function definitions in a header file (unless used in a single cpp file), which would need to be included by consumers then I guess you are exposing the inner workings of your code.

But, since the alternative is usually macros, I doubt that is a good reason against them.


It would certainly be more transparent compared to something compiled into a library or object module. That's because you can see the source code, and therefore write code which manipulates the data structures any way you want.

However, for non-line functions for which you have source, I am at a loss how that could be more protected.

There are software corporations which jealously guard their software source code, and only release object modules to be linked with, or shared libraries, or (dread!) .DLLs.


Inline methods expand all method calls in place. So instead of having foo() be a JMP or CALL instruction it just copies the actual instructions of foo() where it was called. If this contains critical data then that would become exposed although inline functions are typically used for short one to two line methods or larger expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜