This is the mail archive of the gcc@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]

Really, really const


I'm trying to persuade gcc that a memory area is unchanging.  Consider
this:

extern const int a[];
extern void f();

int foo ()
{
  int n = a[0]; 
  f();
  n += a[0];
  return n;
}

Now, I know that a[0] can't change.  But is there any way to tell gcc
that i can't change?  const doesn't seem to do it:

        movl    a, %ebx
        call    f
        addl    a, %ebx

The memory a[0] is read twice.  Is there any attrribute I can use to
stop gcc from doing this?

Andrew.


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