Pointers vs. arrays:  another dumb question...
    Brandon Allbery 
    allbery at ncoast.UUCP
       
    Sun Jun 22 02:52:47 AEST 1986
    
    
  
Expires:
Okay, I've another dumb question for everyone:
In an application I wrote, I use pointers to arrays.  Now:
If the array is malloc'ed, the correct cast is:
		(struct foo (*)[])
and you assign the ``pointer to the array'' to a variable.  But, if it's in
initialized data, you can't do it that way:  you can't take a ``pointer to an
array''.  So the cast is:
		(struct foo *)
BUT:  the arrangement in memory is identical!  It should be even on tagged
architectures, etc.; in fact, (struct foo *) is always wrong, and might
conceivably cause problems on a tagged architecture if you're really pointing
to an array.
So:  why isn't the correct type of an array name (struct foo (*)[])?  That
would make much more clear the meaning of the pointer, and would avoid many of
the pointer-vs.-array confusions.
--Brandon
-- 
ihnp4!sun!cwruecmp!ncoast!allbery ncoast!allbery at Case.CSNET ncoast!tdi2!brandon
(ncoast!tdi2!root for business) 6615 Center St. #A1-105, Mentor, OH 44060-4101
Phone: +01 216 974 9210      CIS 74106,1032      MCI MAIL BALLBERY (part-time)
    
    
More information about the Comp.unix
mailing list