multiple definition of inline function

后端 未结 6 1612
情深已故
情深已故 2020-12-08 19:51

I have gone through some posts related to this topic but was not able to sort out my doubt completely. This might be a very naive question.

I have a header file

6条回答
  •  Happy的楠姐
    2020-12-08 20:47

    The compiling error is because there is a duplicate definition of func1();

    Because func1() is defined using extern inline, it will produce a external definition.

    However, there is also an external definition in tran.c, which cause multiple definition error.

    However, func2() and func3() do not produce an external definition, hence no redefinition error.

    You might want to look at here http://www.greenend.org.uk/rjk/2003/03/inline.html.

    Also, take a note that c++ and c treats inline functions differently, and even in c, different standards (c89 vs. c99) treats inline functions differently.

提交回复
热议问题