home ホーム search 検索 -  login ログイン  | reload edit datainfo version cmd icon diff delete  | help ヘルプ

日記/2010/07/13/ヘッダーファイルの関数宣言にexternって必要?

日記/2010/07/13/ヘッダーファイルの関数宣言にexternって必要?

日記 / 2010 / 07 / 13 / ヘッダーファイルの関数宣言にexternって必要?
id: 704 所有者: msakamoto-sf    作成日: 2010-07-13 23:04:15
カテゴリ: C言語 

cheap2el作ってる時、少し気になってたのでGoogle先生に尋ねてみたら、関数についてはexternをわざわざつける必要は無かったみたいです。

一応ソースの首根っこをメモ。上記Wikipediaから辿れる、"The current Standard (C99 with Technical corrigenda TC1, TC2, and TC3 included)", WG14/N1256 Committee Draft(Septermber 7, 2007) ISO/IEC 9899:TC3 より:

6.2.2 Linkages of identifiers
...
[5] 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.
If the declaration of an identifier for an object has file scope and no storage-class specifier,
its linkage is external.

昔C言語勉強してた時に、libを作る時にincludeするときはextern無しで、外部からリンクする為にincludeするときはextern有りにするとかでわざわざ

#ifdef __BUILD_LIB__
#define Extern extern
#endif
...
Extern int foobar(int a, int b);

とかして、libを作る時と、アプリ側でリンクする時とで define に応じて切り替えてるサンプルを見たことがあったので気になってましたが・・・無意味だったんだなー・・・。


プレーンテキスト形式でダウンロード
現在のバージョン : 1
更新者: msakamoto-sf
更新日: 2010-07-13 23:13:03
md5:6fa57abb15c01e5e796c99a3321ec684
sha1:5364b3b54ec1843222d2f3dbd44cce31d9442465
コメント
コメントを投稿するにはログインして下さい。