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