C言語なら俺に聞け! Part 101
■ このスレッドは過去ログ倉庫に格納されています
0090デフォルトの名無しさん
05/02/01 23:03:41帰ってきたら結論出てるかと思ったのにまだのようなので調べてみたよ。ISO/IEC 9899:1999 より。
> 6.9.1 Function definitions
> 4 The storage-class specifier, if any, in the declaration specifiers
> shall be either extern or static.
となってるので、関数定義につけられる記憶クラスは extern か static だけ。
> 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.
なので、省略時は extern 扱い。
> 6.2.2 Linkages of identifiers
> 4 For an identifier declared with the storage-class specifier extern
> in a scope in which a prior declaration of that identifier is visible,
> if the prior declaration specifies internal or external linkage, the
> linkage of the identifier at the later declaration is the same as the
> linkage specified at the prior declaration. (後略)
となっているので、先行する宣言がある場合の extern は先行する宣言の
リンケージと同じになるから、 static の後の extern は許容された上、
static が優先されると思われ。一方、
> 3 If the declaration of a file scope identifier for an object or a
> function contains the storageclass specifier static, the identifier
> has internal linkage.
> 7 If, within a translation unit, the same identifier appears with both
> internal and external linkage, the behavior is undefined.
となっているので、extern の後の static は ill-formed ではないが、undefined
だと思われ。gcc だと警告が出るね。
■ このスレッドは過去ログ倉庫に格納されています