[42] in java-interest
Semantics of parameter passing
daemon@ATHENA.MIT.EDU (James Cownie)
Thu May 4 12:30:16 1995
Date: Thu, 4 May 1995 10:06:41 +0000
From: jim@meiko.co.uk (James Cownie)
To: java-interest@java.Eng.Sun.COM
JAVA folks,
Please forgive me if I missed it, but I have read the Java Language
Specification (March 15 1995) and can find no description of the
semantics of parameter passing. Beyond the (somewhat unhelpful in this
context) global comment that "When a feature that exists in both Java
and ANSI C isn't explained fully in this specification, the feature
should be assumed to work as it does in ANSI C."
Assuming that things work "as in C", one would expect ALL parameters to
be passed by value. (In C, of course this works for arrays, because
the value of an array is a pointer to its lowest element).
However JAVA doesn't have (user visible) pointers, so there is no
direct analogy. Clearly you don't want to pass arrays by value (as
Pascal did), since this is expensive and useless. But there appears to
be no syntax to control the way in which arguments are passed. (Since
JAVA is more C++ like than C like, I would have expected to see C++
style reference arguments, rather than the C style pointer arguments
which can't exist as there are no pointers).
Looking at the samples of code, it appears that
1) scalars of "simple" types are passed by value
2) arrays are passed by reference
3) scalars of other composite types are also passed by reference.
(*** This would be DIFFERENT from ANSI C or C++, in which classes
are equivalent to structures, and therefore passed by value in the
default case ***).
I think it would be good to define this more explicitly...
A second (minor) point is the statement on page 6 that "All objects
(including arrays) are referred to by pointers that cannot be damaged
by being manipulated as numbers." While I think I understand what this
means, I think the statement could be made clearer by saying something
like
"All objects (including arrrays) are internally referred to by
pointers. However since these pointers can never be converted to
arithmetic types they cannot be damaged by being manipulated as
numbers."
This removes a possible interpretation of the statement as is, that
numeric manipulations on these pointers are possible, but guaranteed
safe.
Thanks in advance for your clarifications.
-- Jim
James Cownie
Meiko Limited Meiko Inc.
650 Aztec West 130C Baker Avenue Ext.
Bristol BS12 4SD Concord
England MA 01742
Phone : +44 1454 616171 +1 508 371 0088
FAX : +44 1454 618188 +1 508 371 7516
E-Mail: jim@meiko.co.uk or jim@meiko.com
WWW : http://www.meiko.com/welcome.html
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com