Loose-Info.com
Last Update 2021/11/06
TOP - 各種テスト - gcc - 警告関連のオプション - -Wnested-externs

-Wnested-externs
関数内でのextern宣言に対して警告を出力

テスト概要

オプション無し、および-Wnested-externsオプションを使用した際の警告出力例

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル


sample.c
#include <stdio.h> /* 関数外でextern宣言 */ extern int n1; int main(void) { /* 関数内でextern宣言 */ extern int n2; return 0; }

動作テスト

オプション無しでコンパイルを実行
$ gcc sample.c 警告無し $

-Wnested-externsオプション使用してコンパイルを実行
$ gcc -Wnested-externs sample.c sample.c: In function ‘main’: sample.c:9:13: warning: nested extern declaration of ‘n2’ [-Wnested-externs] extern int n2; ^~ $ extern宣言がネストされている事についての警告