Using extern keyword to call functions

后端 未结 4 1345
借酒劲吻你
借酒劲吻你 2021-01-21 21:37

I want to call functions defined in test.c from other.c.

Can I extern the function1 to call it? Also, do I have to use extern in <

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 22:19

    Function declarations are "by-default" extern.

    Quoting C11, chapter §6.2.2, (emphasis mine)

    If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern. [...]

    So, you don't need to be explicit about it.

    You need to compile the translation units aka source files (into object files) and then link them together to build the executable. That should do it.

提交回复
热议问题