bug? cannot copy const array

Kazu Hirata kazu@hxi.com
Fri Feb 2 11:24:00 GMT 2001


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






More information about the Gcc-bugs mailing list