Re: C Fronts

Chris Dollin <kers@hplb.hpl.hp.com>
Thu, 8 Aug 91 09:17:29 bst

          From comp.compilers

Related articles
C Fronts whatis@gnu.ai.mit.edu (1991-08-04)
Re: C Fronts MASLOV@VADIK.srcc.msu.su (1991-08-05)
Re: C Fronts MASLOV@VADIK.srcc.msu.su (1991-08-07)
Re: C Fronts kers@hplb.hpl.hp.com (Chris Dollin) (1991-08-08)
Re: C Fronts henry@zoo.toronto.edu (1991-08-09)
Re: C and Fortran semantics and optimization, was C Fronts bob@tera.com (1991-08-12)
| List of all articles for this month |
Newsgroups: comp.compilers
From: Chris Dollin <kers@hplb.hpl.hp.com>
Keywords: C, optimize
Organization: Compilers Central
Date: Thu, 8 Aug 91 09:17:29 bst

In a previous article, MASLOV@VADIK.srcc.msu.su (Vadim Yu. Maslov) writes:


| Example:
|
| DIMENSION A(0:19,0:9) | double a[20][10]; int i,j, func();
| DO 10 i=0,9 | for(i=0; i<10; i++)
| DO 10 j=0,9 | for(j=0; j<10; j++)
| 10 A(i+10,FUNC(j))=A(i,j) | a[i+10][func(j)]=a[i][j];
|
| Such a statement [about the distinctness of a[i+10][func(j)] and
| a[i][j]] can not be made regarding C program on the right side. Since
| any values of func(j) are valid (including values that don't fit into
    ^^^^^^^^^^^^^^^^^^^^^
| 'boundaries', say, -20), references a[i+10][func(j)] and a[i][j] can
| point to the same location. So this C loop can not be parallelized using
| only information that we have in this fragment.


Unless I misunderstand the ANSI standard (entirely possible; better people
than I do so), the marked statment is invalid; it is *not* legal to index an
array outside its bounds in C. For example, ``a[10][-1]'' is illegal, even
though blindly performing the address calculation would get a reference inside
the array.


Traditional C compilers do *no* array-bounds checking, and 2-d array
allocation is defined to be done as arrays-of-arrays; this means that such
subscripting tricks can ``work'', even though they are illegal. I think that
an optimising C compiler is entitled to treat the C code in the same fashion
as the Fortran compiler treats the Fortran code (modulo, perhaps, stuff about
whether ``func'' can be assumed to be stateless).


Kers.
[ANSI does indeed forbid out-of-range subscripts, though I suspect that a
C implementation that rejected them would fail many putatively working
programs. It is a longstanding problem with C, and indeed with many other
languages, that programmers tend to confuse warts of the local implementation
with the definition of the language. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.