Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: ptrs and arrays Message-ID: <20671@mimsy.umd.edu> Date: 10 Nov 89 04:50:22 GMT References: <2640@dogie.macc.wisc.edu> <63332@psuecl.bitnet> <20527@mimsy.umd.edu> <0156@sheol.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 50 In article <0156@sheol.UUCP> throopw@sheol.UUCP (Wayne Throop) writes: >As is (essentially) invariably the case, the argument Chris presents >against the usefulness of utterable array types of unknown size is >both cogent and correct. I think it misses a small point, however. I did this deliberately: >The point is controlled information hiding. I have a (perhaps weak) argument against this particular usage. I was going to include it, but cannot think of any decent way to phrase it (this is one of the reasons I cannot tell whether it is really any good). All I can do is point out something about the wording here: >Such types (it seems to me) are perfectly appropriate in header files, >where the decision of actual array size can be delayed until link time >safely, In other words, we have something like extern sometype somearray[]; /* unknown size */ This much is justifiably necessary---among other things, it is the right way to refer to variables such as `sys_siglist' and `etext' (these are specific to Unix, but no doubt there are other examples). >and yet provide for some operations (encapsulated in macros >defined in the same header file preferably) on the element type of the >array. But look at what you just said: operations on the *element type* of the array: not operations on the array as a whole. Operations on these elements need pointers to the elements, not a pointer to the array. To put it another way (in another weak argument), I have never seen a situation where I could justify `sometype (*p)[]', even when dealing with someone else's array, whose type I knew, but size I did not. Moreover, I have had to know that something was an array type, even when its elements were hidden. For instance, `jmp_buf' must be an array type. The `array-ness' of an object shows through, because only arrays can be modified by a call that does not have an `&': f(x); /* x is never modified, but x[i] could be */ f(&x); /* x could be modified (and x[i] could be as well) */ Arrays often get short shrift in C, and I think this applies to information hiding as well. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris