Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!texbell!sugar!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: Why does C hate 2d arrays? Message-ID: Date: 25 May 90 15:14:33 GMT References: <12919@smoke.BRL.M> <3035@goanna.cs.rmit.oz.au> <505:May2220:21:2290@stealth.acf.nyu.E> <_BN3F_F@xds13.ferranti.C> <8696:May2401:55:1290@stealth> <12923:May2502:17:3090@ Reply-To: peter@ficc.ferranti.com (Peter da Silva) Distribution: usa Organization: Xenix Support, FICC Lines: 63 In article <12923:May2502:17:3090@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: > In article peter@ficc.ferranti.com (Peter da Silva) writes: > > [assume: array[m][n] works for m and n not constants] > > What possible advantage would there be to requiring that m and n not > > change value while array is in scope? > The compiler isn't *forced* to make extra, possibly unnecessary, copies > of m and n. The compiler is not forced to make extra copies of m and n either way. Only if they're found to have changed. > > Since m andd n can be expressions, > > you are going to want to stash the values away anyway just for the sake > > of optimisation. > Not necessarily: m and n may be in registers anyway. To generalize a > bit: C is a constant, calculated from expression E. We have to know the > value of C for the lifetime of A. ``Therefore,'' you say, ``we must pick > an arbitrary time in that lifetime, calculate E then, and stash it away > in C's special hiding place.'' If you want to guarantee that C is to remain constant during the duration of E. What about this case: struct _point { int x, y }; foo(box) struct point box[2]; { char tmp[box[1].x - box[0].x][box[1].y - box[0].y]; bar(box, tmp); print(box, tmp); } How do you guarantee that box is constant? In general, you can't. This is back to the old noalias problem. Better sidestep it completely by just using the value of box at declaration. > Do you agree that, given this scenario, it's better for the programmer > to have access to C's value than not? How do you feel about: char *a = malloc(some_expression); How does this materially differ from: char a[some experssion]; in the context of this discussion? Do you agree that, given this scenario, it's better for the programmer to have access to !some expression!'s value than not? Whether you're mallocing or not. > In other words, do you agree that > C should be explicitly declared and initialized by the programmer? It may be good programming practice, but this is C, not Pascal. C is expected to bend over backwards to do weird stuff that flakey programmers might want to do. -- `-_-' Peter da Silva. +1 713 274 5180. 'U` Have you hugged your wolf today? @FIN Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.