This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Can a const-qualified array be cast to const void * and back?
- From: Alexey Neyman <avn at emcraft dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 15 Jul 2007 12:12:59 +0400
- Subject: Can a const-qualified array be cast to const void * and back?
Hi all,
I am confused why in the code below, an assignment from "const void *" to
a pointer to const array causes a "discards qualifiers" warning. Could
someone please help? How should the fp_t type qualified so that it
doesn't cause warnings?
<<<<
const int f[][3] = { { 1, 2, 3 } };
const void *pf = &f;
typedef const int (*fp_t)[][3];
fp_t xx, yy;
void g(void)
{
xx = &f; /* Ok */
yy = pf; /* initialization discards qualifiers from pointer
target type */
}
<<<<
$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)
Best regards,
Alexey Neyman.