K
Kobu
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).
"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).