これは、私がインターネットで見つけた断片をまとめたものです。私の見方は歪んでいるかもしれません。
いくつかの基本的な例。
int x;
// The type specifer is int
// Declarator x(identifier) defines an object of the type int
// Declares and defines
int x = 9;
// Inatializer = 9 provides the initial value
// Inatializes
C11 標準 6.7 では、識別子の定義は、次のような識別子の宣言です。
— オブジェクトの場合、ストレージがそのオブジェクト用に予約されます。
— 関数の場合、関数本体が含まれます。
int main() // Declares. Main does not have a body and no storage is reserved
int main(){ return 0; }
// Declares and defines. Declarator main defines
// an object of the type int only if the body is included.
以下の例
int test(); Will not compile. undefined reference to main
int main(){} Will compile and output memory address.
// int test();
int main(void)
{
// printf("test %p \n", &test); will not compile
printf("main %p \n",&main);
int (*ptr)() = main;
printf("main %p \n",&main);
return 0;
}
extern int a; // Declares only.
extern int main(); //Declares only.
extern int a = 9; // Declares and defines.
extern int main(){}; //Declares and defines. .