"宣言"与“定义”相对 [英] "Declaration" vs. "Definition"
问题描述
我的问题是关于术语声明的用法和含义。和
定义因为它与C语言有关。
我在阅读有关这样的事情时,我已经阅读了两者混合的消息来源
为一个存储设置存储空间对象,定义/声明一个结构,部分
函数,引用另一个模块中的外部变量。
sourcefile1.c
==============
extern long globalfoo; /* 宣言? * /
int main()
{
浮b; /* 宣言 ? * /
struct STRUCTFOO
{
int foobar;
}; / *定义? * /
struct STRUCTFOO foostruct; /* 宣言? * /
返回0;
}
sourcefile2.c
= ============
long globalfoo; / *定义实例?? Steve Summit教程称之为
这个* /
-
我使用的简单规则是,如果它放在一边存储它是'b $ b声明,否则它是一个定义。
即使有这个规则,功能似乎也不同。我们称之为
原型声明和标题/正文定义(即使这是'/ b $ b'它是标题/正文放置代码空间)。
My question is about the use and meaning of the terms "declaration" and
"definition" as it pertains to the C language.
I''ve read sources that mix the two up when talking about such things as
setting aside storage for an object, defining/declaring a struct, parts
of a function, referencing an external variable in another module.
sourcefile1.c
==============
extern long globalfoo; /* declaration? */
int main()
{
float b; /* declaration ? */
struct STRUCTFOO
{
int foobar;
}; /* definition ? */
struct STRUCTFOO foostruct; /* declaration? */
return 0;
}
sourcefile2.c
=============
long globalfoo; /* defining instance?? Steve Summit tutorial calls it
this */
--
The simple rule I use is that, if it sets aside storage it''s a
declaration, otherwise it''s a definition.
Even with this rule, functions seem to be different. We call
prototypes declarations, and headers/bodies definitions (even though
it''s the header/body that sets aside code space).
推荐答案
" Kobu" < KO ******** @ gmail.com>在消息中写道
news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
"Kobu" <ko********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我的问题是关于术语声明的用法和含义。和
定义因为它与C语言有关。
在阅读诸如为对象预留存储空间,定义/声明结构,函数的部分,引用另一个模块中的外部变量。
sourcefile1.c
==============
extern long globalfoo; /* 宣言? * /
是的。
int main()
{/ b>浮动b; /* 宣言 ? * /
是的。也是一个定义。
struct STRUCTFOO
{foobar;
}; / *定义? * /
是的。 ''类型定义''。
结构STRUCTFOO foostruct; /* 宣言? * /
是的。也是一个定义。
返回0;
}
sourcefile2.c
=============
long globalfoo; / *定义实例??史蒂夫峰会教程称之为
这* /
定义(也是声明)。
-
我使用的简单规则是,如果它留出存储它是一个声明,否则它是一个定义。
是的。除了一个结构定义,它是一个''类型定义'',
并没有分配存储(但结构定义可以组合
与定义一个结构类型的对象:
struct x
{
int a;
} s ;
定义类型''struct x''以及该类型的对象。
即使有这个规则,函数似乎不一样。
是的。函数定义与
a函数定义不一样。
我们调用
原型声明,
是的,但声明不一定是原型。
和标题/正文定义(即使
它是标题/正文放置代码空间。)
My question is about the use and meaning of the terms "declaration" and
"definition" as it pertains to the C language.
I''ve read sources that mix the two up when talking about such things as
setting aside storage for an object, defining/declaring a struct, parts
of a function, referencing an external variable in another module.
sourcefile1.c
==============
extern long globalfoo; /* declaration? */
Yes.
int main()
{
float b; /* declaration ? */
Yes. Also a definition.
struct STRUCTFOO
{
int foobar;
}; /* definition ? */
Yes. A ''type definition''.
struct STRUCTFOO foostruct; /* declaration? */
Yes. Also a definition.
return 0;
}
sourcefile2.c
=============
long globalfoo; /* defining instance?? Steve Summit tutorial calls it
this */
A definition (also a declaration).
--
The simple rule I use is that, if it sets aside storage it''s a
declaration, otherwise it''s a definition.
Yes. Except for a struct definition, which is a ''type definition'',
and does not allot storage (but a struct definition can be combined
with a definition of an object of that struct type:
struct x
{
int a;
} s;
defines type ''struct x'' as well as an object of that type.
Even with this rule, functions seem to be different.
Yes. A function definition is not the same thing as
a function definition.
We call
prototypes declarations,
Yes, but a declaration need not be a prototype.
and headers/bodies definitions (even though
it''s the header/body that sets aside code space).
它是{和}以及它们之间的代码,组合
带有''函数头''(名称和参数列表),
,它们包含一个函数定义。
-Mike
It''s the { and } and the code between them, combined
with the ''function header'' (name and argument list),
which comprise a function definition.
-Mike
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
新闻:1V **************** @ newsread1.news.pas.earthli nk.net ...
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:1V****************@newsread1.news.pas.earthli nk.net...
Kobu < KO ******** @ gmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
"Kobu" <ko********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我的问题是关于术语声明的用法和含义。和
定义因为它与C语言有关。
在阅读诸如为对象预留存储空间,定义/声明结构,函数的部分,引用另一个模块中的外部变量。
sourcefile1.c
==============
extern long globalfoo; /* 宣言? * /
是的。
My question is about the use and meaning of the terms "declaration" and
"definition" as it pertains to the C language.
I''ve read sources that mix the two up when talking about such things as
setting aside storage for an object, defining/declaring a struct, parts
of a function, referencing an external variable in another module.
sourcefile1.c
==============
extern long globalfoo; /* declaration? */
Yes.
浮动b; /* 宣言 ? * /
int main()
{
float b; /* declaration ? */
是的。也是一个定义。
Yes. Also a definition.
不,这是一个定义。
No, its a definition.
struct STRUCTFOO
{
int foobar;
}; / *定义? * /
是的。一个''类型定义''。
struct STRUCTFOO
{
int foobar;
}; /* definition ? */
Yes. A ''type definition''.
不,这是一个声明。
No, Its a declaration.
struct STRUCTFOO foostruct; /* 宣言? * /
是的。也是一个定义。
struct STRUCTFOO foostruct; /* declaration? */
Yes. Also a definition.
不,这是一个定义。
No, its a definition.
返回0;
}
sourcefile2.c
=============
long globalfoo; / *定义实例?? Steve Summit教程称之为
这个* /
一个定义(也是一个声明)。
return 0;
}
sourcefile2.c
=============
long globalfoo; /* defining instance?? Steve Summit tutorial calls it
this */
A definition (also a declaration).
-
我使用的简单规则是,如果它放置存储它是声明,否则它是一个定义。
--
The simple rule I use is that, if it sets aside storage it''s a
declaration, otherwise it''s a definition.
否,相反。
"定义"指的是创建或分配变量的地方
存储; "宣言"指变量的性质为
的地方,但没有分配存储空间。 -K& R II Page 33
所以,我们可以说定义也是一个宣言。我是对的吗?
是的。除了结构定义,它是一个''类型定义'',
并没有分配存储(但结构定义可以组合
与该结构类型的对象的定义:
结构x
{
int a;
} s;
定义类型''struct x''以及它的对象类型。
No, The Opposite.
"Definition" refer to the place where the variable is created or assigned
storage; "Declaration" refers to places where the nature of the variable is
stated but no storage is allocated." -K&R II Page 33
So, We can say Definition is also a Declaration. Am I right?
Yes. Except for a struct definition, which is a ''type definition'',
and does not allot storage (but a struct definition can be combined
with a definition of an object of that struct type:
struct x
{
int a;
} s;
defines type ''struct x'' as well as an object of that type.
即使有这个规则,功能似乎也不同。
是的。功能定义与功能定义不同
功能定义。
Even with this rule, functions seem to be different.
Yes. A function definition is not the same thing as
a function definition.
你的意思是什么???
What do U mean by this???
我们称之为
原型声明,
We call
prototypes declarations,
是的,但声明不一定是原型。
Yes, but a declaration need not be a prototype.
和标题/正文定义(即使它是
它'是标题/正文放置代码空间。)
and headers/bodies definitions (even though
it''s the header/body that sets aside code space).
它是{和}以及它们之间的代码,与''函数结合使用头''(名称和参数列表),
包含一个函数定义。
It''s the { and } and the code between them, combined
with the ''function header'' (name and argument list),
which comprise a function definition.
-Mike
- Neo
-Neo
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
新闻:1V **************** @ newsread1.news.pas.earthli nk.net ...
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:1V****************@newsread1.news.pas.earthli nk.net...
Kobu < KO ******** @ gmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
"Kobu" <ko********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我的问题是关于术语声明的用法和含义。和
定义因为它与C语言有关。
在阅读诸如为对象预留存储空间,定义/声明结构,函数的部分,引用另一个模块中的外部变量。
sourcefile1.c
==============
extern long globalfoo; /* 宣言? * /
是的。
My question is about the use and meaning of the terms "declaration" and
"definition" as it pertains to the C language.
I''ve read sources that mix the two up when talking about such things as
setting aside storage for an object, defining/declaring a struct, parts
of a function, referencing an external variable in another module.
sourcefile1.c
==============
extern long globalfoo; /* declaration? */
Yes.
浮动b; /* 宣言 ? * /
int main()
{
float b; /* declaration ? */
是的。也是一个定义。
Yes. Also a definition.
不,这是一个定义。
No, its a definition.
struct STRUCTFOO
{
int foobar;
}; / *定义? * /
是的。一个''类型定义''。
struct STRUCTFOO
{
int foobar;
}; /* definition ? */
Yes. A ''type definition''.
不,这是一个声明。
No, Its a declaration.
struct STRUCTFOO foostruct; /* 宣言? * /
是的。也是一个定义。
struct STRUCTFOO foostruct; /* declaration? */
Yes. Also a definition.
不,这是一个定义。
No, its a definition.
返回0;
}
sourcefile2.c
=============
long globalfoo; / *定义实例?? Steve Summit教程称之为
这个* /
一个定义(也是一个声明)。
return 0;
}
sourcefile2.c
=============
long globalfoo; /* defining instance?? Steve Summit tutorial calls it
this */
A definition (also a declaration).
-
我使用的简单规则是,如果它放置存储它是声明,否则它是一个定义。
--
The simple rule I use is that, if it sets aside storage it''s a
declaration, otherwise it''s a definition.
否,相反。
"定义"指的是创建或分配变量的地方
存储; "宣言"指变量的性质为
的地方,但没有分配存储空间。 -K& R II Page 33
所以,我们可以说定义也是一个宣言。我是对的吗?
是的。除了结构定义,它是一个''类型定义'',
并没有分配存储(但结构定义可以组合
与该结构类型的对象的定义:
结构x
{
int a;
} s;
定义类型''struct x''以及它的对象类型。
No, The Opposite.
"Definition" refer to the place where the variable is created or assigned
storage; "Declaration" refers to places where the nature of the variable is
stated but no storage is allocated." -K&R II Page 33
So, We can say Definition is also a Declaration. Am I right?
Yes. Except for a struct definition, which is a ''type definition'',
and does not allot storage (but a struct definition can be combined
with a definition of an object of that struct type:
struct x
{
int a;
} s;
defines type ''struct x'' as well as an object of that type.
即使有这个规则,功能似乎也不同。
是的。功能定义与功能定义不同
功能定义。
Even with this rule, functions seem to be different.
Yes. A function definition is not the same thing as
a function definition.
你的意思是什么???
What do U mean by this???
我们称之为
原型声明,
We call
prototypes declarations,
是的,但声明不一定是原型。
Yes, but a declaration need not be a prototype.
和标题/正文定义(即使它是
它'是标题/正文放置代码空间。)
and headers/bodies definitions (even though
it''s the header/body that sets aside code space).
它是{和}以及它们之间的代码,与''函数结合使用头''(名称和参数列表),
包含一个函数定义。
It''s the { and } and the code between them, combined
with the ''function header'' (name and argument list),
which comprise a function definition.
-Mike
- Neo
-Neo
这篇关于"宣言"与“定义”相对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!