Re: A clarification please
- From: Barry Schwarz <schwarzb@xxxxxxxx>
- Date: Mon, 18 Aug 2008 16:48:34 -0700
On Mon, 18 Aug 2008 15:23:06 -0700 (PDT), mdh <mdeh@xxxxxxxxxxx>
wrote:
FAQ 1.7 shows that, amongst other things,
int i = 0;
is a definition.
Page 128 of K&R say:
"A struct declaration defines a type. The right brace that terminates
the list of members may be followed by a list of variables, just as
for any basic type. That is,
struct {.....} x, y, z:
is syntactically analogous to
int x, y, z;
in the sense that each statement declares x, y, and z to be variables
of the named type **and causes space to be set aside for them**. {My
emphasis}
My understanding was that a definition causes space to be set aside,
( eg int i = 0) but not a declaration ( eg int i) and the x, y, and z
in the above example. How can these two ideas be reconciled?
By correcting your understanding.
int i; is a definition. It causes space to be set aside (in some
implementation specific sense of the phrase) for object i. If it
didn't, code such as i = j+k; would have no place to store the result.
extern int i; is a declaration. It promises that i is in fact defined
somewhere else and the linker will be able to resolve its location.
struct t {...}; is a declaration. It doesn't define an object. It
does "define" a new type. (I prefer to say it declares the type but
it's hard to argue with K&R.) In any event, defining a type is
different than defining an object or function. struct t {...} x; is a
definition. It defines the object x and reserves space for it.
All of which proves that the word "define" and words derived from it
mean different things when used to describe the creation of objects or
used to describe other aspects of the language.
This is not that unusual. The word "token" means different things
when talking about the preprocessor, language syntax, or the use of
the standard function strtok. Context is important when trying to
decide what things mean.
--
Remove del for email
.
- Follow-Ups:
- Re: A clarification please
- From: mdh
- Re: A clarification please
- References:
- A clarification please
- From: mdh
- A clarification please
- Prev by Date: Re: bmp file issues
- Next by Date: Re: Why is it dangerous?
- Previous by thread: Re: A clarification please
- Next by thread: Re: A clarification please
- Index(es):
Relevant Pages
|