[3542] in java-interest

home help back first fref pref prev next nref lref last post

Re: declaration v.s. definition ambiguity

daemon@ATHENA.MIT.EDU (Michael Daconta)
Wed Nov 15 21:11:47 1995

Date: Wed, 15 Nov 1995 16:09:32 -0700 (MST)
To: garya@village.org (Gary Aitken), java-interest@java.sun.com
From: daconta@PrimeNet.Com (Michael Daconta)

At 09:47 PM 11/13/95 -0700, Gary Aitken wrote:
>>declaration: Only an announcement to the compiler of an identifier to be
>>reserved in the current name space. In ANSI C, accomplished with the
>>extern keyword.  For functions accomplished by omitting the function body.
>>For structures and classes accomplished with type identifier and no body.
>
>>definition: An announcement to the compiler of an identifier to be
>>reserved in the current name space.  For primitive types, accompanied
>>with a reservation of storage space.  For user-defined types,
>>accomplished by specifying the structure or class body.  For functions
>>accomplished by specifying the function body.
>
>If I read the above correctly, the following is a declaration of Foo,
>not a definition:
>
>	public static void main ( String argv[] ) {
>		MyClass	foo;
>	}
>
>But it seems to me this is a definition.
>Also, abstract methods cannot have a body (unfortunately; should be may not)

Hi Gary, 
        In the above, the 
                MyClass foo; 
        is only a definition if MyClass has already been defined which
I'm sure is what you meant.

>
>As I understand the current syntax and semantics, 
>it seems to me that a declaration is:
>
>	An announcement to the compiler of an identifier to be reserved 
>	in the current name space, with no storage allocation.
>
>and a definition is:
>
>	An announcement to the compiler of an identifier to be reserved
>	in the current name space, together with the reservation of
>	storage for the identifier.
>
>If we remember to take into account the difference between a class, and
>an instance of a class, the above is all consistent.  In a class definition,
>the storage is allocated for the class itself -- the stuff which implements
>the class; not an instance of the class.

I think you are close; however, I don't think there is actually any storage
allocated for "the stuff which implements the class."  Not at runtime anyway.
At compile time there is of course symbol table entries.  However,
I think the ANSI C distinction of storage allocation was referring to
runtime allocation.

However, I think you are correct in that you need to take into an account
that a class is different than a primitive type.  A class definition is
much closer to a function definition than a primitive type definition.
Using the analogy of a function definition seems to clear it up for
me.

>
>	A class, in java, is never just declared.  It is declared
>	and defined in one operation.  The definition amounts to allocating
>	storage for all aspects of the class which do not require additional
>	storage allocation when an object of the class is instantiated.
>
>	A class instantiation, such as the "MyClass foo;" above, is a
>	definition, as it reserves the storage associated with the instance.
>
>	An interface, in java, is always declared, but never defined,
>	since the definition of an interface is dependent on the class
>	which implements the interface; a definition for an interface 
>	effectively occurs in the context of a class which implements 
>	the interface.
>
>Does this make sense?
>And please remember I'm no expert on this -- Arthur or somebody else
>should pass judgement on any statements like the ones I made above.
>
>Gary Aitken		garya@village.org
>

Gary I think your definitions are good.  Of course, when you say,
"It is declared and defined in one operation," that is not technically
correct because a definition is a declaration.  That is why they are
so often used interchangeable.  It is perfectly legal to say that for

  int a;

the identifier a is declared in this namespace.
int a is a definition but a definition is a declaration so,
(using logic) if A=B=C then A=C.

I have it down now.  Thanks for your help.

 - Mike

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post