How to correctly use the extern keyword in C

后端 未结 10 2264
感情败类
感情败类 2020-11-22 08:11

My question is about when a function should be referenced with the extern keyword in C.

I am failing to see when this should be used in practice. As I

10条回答
  •  攒了一身酷
    2020-11-22 08:29

    It has already been stated that the extern keyword is redundant for functions.

    As for variables shared across compilation units, you should declare them in a header file with the extern keyword, then define them in a single source file, without the extern keyword. The single source file should be the one sharing the header file's name, for best practice.

提交回复
热议问题