Re: Warning when using const pointer to fixed size array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/11/30 Aaron Rocha <hxdg21@xxxxxxxxx>:
>
> Back to my original question though. Why does gcc give that warning? It
> should be legal to point a const pointer to a non-const variable and use
> the pointer for read-only access, right? So why the warning? Is this a bug
> in GCC?
>

I'm unsure, but it's possible that the problem is that you're not
using a pointer to a const array of non-mutable elements, but a
pointer to non-const array with const elements.  (I have no idea how
"deep" const is with array types.)

It makes me think of this situation, though I don't know whether it applies:
http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17

But that said, apparently this gives the warning too:

  int main() {
    typedef int atype[9];
    atype array = {};
    atype const* const p = &array;
    return (*p)[0];
  }

Which definitely wouldn't for a non-array type.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux