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

RE: bug? cannot copy const array


Title: RE: bug? cannot copy const array

Hi,

> int main()
> {
>    // works;
>    const int constint = 7;
>    int nint = constint;
>
>    // so why not this?
>    const int constarrayint[3] = { 1, 2, 3 };
>    int arrayint[3];
>    arrayint = constarrayint;
> }
>
> It complains:
>
> bug.cpp:10: incompatible types in assignment of `const
> int[3]' to `int[3]'
>
> Surely this is a bug, since you can copy a const int to an int, no?

If you say constarrayint, then that's equivalent to &constarrayint[0].  Likewise, arrayint is equivalent to &arrayint[0].  If you want to copy the entire array, use a for loop or memcpy.

Kazu Hirata


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