Re: C Pointer Arithmetic -> Array Reference (Richard Schooler)
Mon, 19 Sep 1994 14:36:14 GMT

          From comp.compilers

Related articles
C Pointer Arithmetic -> Array Reference (Etienne GAGNON) (1994-09-17)
Re: C Pointer Arithmetic -> Array Reference (1994-09-19)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Richard Schooler)
Keywords: analysis, optimize
Organization: HP/Apollo Massachusetts Language Lab
References: 94-09-092
Date: Mon, 19 Sep 1994 14:36:14 GMT

Etienne GAGNON <> writes:

      Does anyone know about books, articles or papers written on
      converting pointer arithmetic to array reference automatically?

      e.g.: main() ===>> main()
                              { {
                                  int a[100]; int a[100];
                                  int *p; int *p;
                                  int i; int i;

                                  p = a; p = a;
                                  for( i=0; i<100; i++ ) for( i=0; i<100; i++ )
                                      { {
                                          *p = 0; ===>> /* pointer arithmetic p++ removed */
                                          p++; ===>> a[i] = 0; /* or p[i]=0 */
                                      } }
                              } }

Why would you want to do such a thing? To be able to do dependence
analysis, loop transforms, etc.? If so, I would recommend the approach of
compiling into canonical forms that abstract away the difference between
the pointer and array source forms. For instance, doing induction
variable analysis essentially does the above transform, in that it
"decorates" the use of "p" with the information that this expression has
an initial value of "&a", and that it increments by "sizeof(int)" every
time around the loop. A little type-based delinearization for
multi-dimensional arrays, and you're done!
                -- Richard
Richard Schooler Hewlett-Packard 300 Apollo Drive
(508) 436-5452 fax:5135 Chelmsford, MA 01824

Post a followup to this message

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