This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++] More fun with constructors and latent bugs


Richard Henderson <rth@redhat.com> writes:

| On Fri, Dec 17, 2004 at 03:06:31AM +0100, Gabriel Dos Reis wrote:
| > | 	* init.c (build_zero_init): max_index is the number of
| > | 	elements, minus 1.
| > 
| > What are the design rationale behind this choice (Steven, I'm not
| > sayint you're at fault).  That is a serious question.
| 
| The domain is the min:max valid indicies, for one, because otherwise
| you can't represent a byte array covering the entire address space
| using size_t as the index type.

Many thanks for the explanations.

| On the other hand, we get miserable code from variable sized 
| multidimensional arrays from it.  We wind up with stuff like
| 
| 	int A[n][n];
| 	...
| 	x = A[i][j];
| ->
| 	tmp.1 = n - 1;
| 	tmp.2 = n - 1;
| 	...
| 	tmp.3 = tmp.1 * 4;
| 	tmp.4 = tmp.3 + 4;
| 	tmp.5 = tmp.4 * i;
| 	tmp.6 = tmp.5 + &A;
| 	x = tmp.6[j];
| 
| at least from the C front end.  Sort of inexcusable, really.
| No need for us to have subtracted 1 in the first place only
| to have to put it back again.
| 
| I'm not 100% certain why an address-space-filling array is
| a design criteria.  Probably because Ada requires you to be
| able to declare one.  On the other hand, I defy you to find
| out if it actually works once you've compiled it.

:-(

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]