Warning when using const pointer to fixed size array
Thomas Martitz
thomas.martitz@student.HTW-Berlin.de
Mon Nov 30 23:38:00 GMT 2009
Am 01.12.2009 00:19, schrieb Aaron Rocha:
> I am using :
>
> $ gcc -dumpversion
> 4.2.4
> $ gcc -dumpmachine
> x86_64-linux-gnu
>
> As expected, the following code does not generate any warnings when compiling with -Wall:
>
> int main() {
>
> int number = 0;
>
> const int * const t =&number;
>
> return *t;
> }
>
> However, this code does:
>
> int main() {
>
> int array[9] = {0};
>
> const int (* const p)[9] =&array;
>
What address are you taking? "array" already stands for the address of
the first element (and is hence sort of a pointer). I'm not sure you can
take the address of the array name as I think it doesn't have one.
Maybe you want &array[0]?
More information about the Gcc-help
mailing list