入れ子関数がgccの拡張機能としてサポートされていますが、cファイルを使用してネストされた関数をエラーでコンパイルしました。 エラーのマッサージは、このようなものです:入れ子関数で使用されるcファイルをコンパイルするときにエラーが発生しました
test.cpp:6:40: error: function definition is not allowed here double
square (double z) { return z * z; }
そして、ネストされた関数は、このようなものです:
foo (double a, double b)
{
double square (double z) { return z * z; }
return square (a) + square (b);
}
私のオペレーションシステムは、Mac OSであり、私はgcc -v
を入力すると、バージョンは10.12.6
ですiTerm2の場合、応答は次のとおりです。
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
http://en.cppreference.com/w/c/language/function_definition: * "関数宣言とは異なり、関数定義はファイルスコープでのみ使用できます(入れ子関数はありません)。* – UnholySheep
clangはgccが必要な入れ子関数をサポートしていません。 –
Appleの「gcc」は 'clang'の単なるエイリアスです。 – molbdnilo