mixing pointers and arrays
alan at allegra.UUCP
alan at allegra.UUCP
Tue Aug 16 02:15:15 AEST 1983
I think my ideas about arrays being passed by value were misunderstood,
at least by one person. A follow-up article made these points:
(1) Almost all existing programs would have to be rewritten,
since the change would not be upward compatible.
(2) If all arrays are passed by value, then character strings
must be passed by value as well (after all, they are arrays
of characters). This means
(a) programs will be slower, so that the copy can be made,
(b) programs will be bigger, for a place to copy to,
(c) subroutines that modify a character string in place
(like strcpy) will stop working.
Yes, this fix to the language would break a lot of programs, but if the
change were made, and the broken programs fixed, they would not be any
less efficient than they were before, and routines like strcpy would still
work just fine.
len = strlen(s);
would just be replaced with
len = strlen(&s);
I'm certainly not saying arrays should always be passed by value. People
pass pointers to structures all the time, even though they could pass the
structure by value, if they chose. I would just like the same choice with
arrays. It would make the language simpler, clearer, and more consistent.
Alan Driscoll
Bell Labs, Murray Hill
More information about the Comp.lang.c
mailing list