Address of array

Gregory Smith greg at utcsri.UUCP
Sat Mar 22 03:53:13 AEST 1986


In article <313 at hadron.UUCP> jsdy at hadron.UUCP (Joseph S. D. Yao) writes:
>I don't really see what the problem is that people are moaning
>about.  If you want a pointer to the array, the array name itself
>coerces to a pointer containing the memory location at the beginning
	       ^^^^^^ ( right value wrong type. no cigar. )
>of the array.  There is no such thing as a pointer to the whole
>array:  that is a Pasqualische or Fortranian notion.  Pointers, in
>C, only point to atomic or aggregate (structure/union) objects.

Poppycock!
	char *char_ptr, (*char_ar_ptr)[80];

	++ char_ptr;	/* add 1 to the actual value of char_ptr */
	++ char_ar_ptr; /* add _80_ to the actual value of char_ar_ptr */
			/* i.e. point to the next array in a list */

IF I can have a pointer to an array, and dereference it to get an array,
and increment it to point at the next array, WHY THE $@%@ CAN'T I POINT THE
&#&*@&* THING AT AN ARRAY!!!!!!!?????????? ( nicely, I mean )

	char line[80];	/* this is what I want to point it at */

	char_ar_ptr = &line;		/* this should work ... */
	char_ar_ptr = line;		/* this works, but gets a warning */
					/* ( and rightly so ) */
	char_ar_ptr = (char(*)[80])line; /* this works (big %$@%# deal) */

Furthermore, I don't buy the argument that array names are really load-time
constants. I am mentioning this only because I have heard this argument more
than once. I  fail to see any logic underlying this; perhaps somebody treated
array names as constants in some embryonic implementation of C because it
worked for that definition of the language. No excuse. Anyway, array names
are not always constants; any array which is local to a function has an address
which is relative to the frame pointer. Also, in

	struct foo{ int foodle; char foo_line[80]; } *foo_ptr;

the ARRAY foo_ptr->foo_line doesn't have a constant address, does it?

The prosecution rests ( for now ).
-- 
"No eternal reward will forgive us now for wasting the dawn" -J. Morrison
----------------------------------------------------------------------
Greg Smith     University of Toronto       ..!decvax!utzoo!utcsri!greg



More information about the Comp.lang.c mailing list