C: What is the use of 'extern' in header files?

后端 未结 3 1384
清歌不尽
清歌不尽 2020-12-30 04:19

Pardon me if this sounds a question that has been asked many times but I assure you this is a little different.

I use Codeblocks for C programming and lately I have

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 04:43

    Providing function declarations in a header will at least protect you from stupid errors like passing arguments of incompatible types.

    Moreover, headers are used not only for function declarations. What's about struct/enum definitions, global typedefs, macros, inline functions, etc?

    Finally, header can be considered as an external API for your module. One can briefly take a look at a header to understand how to use it without dealing with an implementation (which sometimes is not available at all).

提交回复
热议问题