Can a const-qualified array be cast to const void * and back?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux