Address of array

Guy Harris guy at sun.uucp
Fri Apr 4 04:31:55 AEST 1986


> struct and array pass-by-value and return - a moderate view:
> Structures should always be passed by reference. Usually you only need
> to look at fields, and if you need scratch space then you should declare
> local variables. (Modify this for structs that fit in small packages,
> like struct { short x,y; }).

For efficiency reasons yes, they should be passed by reference in many
circumstances.  However, the language already supports call-by-value, and it
can be convenient in many other circumstances, so use or non-use of
call-by-value should be a matter of programming style, not of language
definition.

> Structure and array assignment, and comparison for equality, without buffer
> copies is a good thing.

You are aware, of course, that comparison for equality of structures,
assuming it were added to the language, could not be implemented by a
"string compare" instruction or code sequence?  Such a sequence would
compare the padding bytes between structure members; there is no guarantee
that those bytes are ever initialized, so two structures whose values are
equal may not contain identical bit patterns.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.arpa	(yes, really)



More information about the Comp.lang.c mailing list