This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13980] New: Can't assign a predefined const int 0 to a pointer
- From: "warp at iki dot fi" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Feb 2004 14:57:22 -0000
- Subject: [Bug c++/13980] New: Can't assign a predefined const int 0 to a pointer
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
According to Stroustrup's "The C++ progamming language" this should work ok:
const int NullPtr=0;
void foo()
{
char* s = NullPtr;
}
However, g++ issues the error message "invalid conversion from `int' to `char*'"
(regardless of the compiler options used).
Curiously, these assignments do not cause an error:
char* s = (const int)NullPtr;
char* s = (int)NullPtr;
gcc -v prints the following here:
Reading specs from
/opt/local/lang/gcc331-sol7/lib/gcc-lib/sparc-sun-solaris2.7/3.3.1/specs
Configured with: ../../gcc-3.3.1/configure --prefix=/opt/local/lang/gcc331-sol7
--enable-shared --enable-cpp --disable-threads --with-gnu-ld
--with-ld=/opt/local/lang/gcc331-sol7/bin/ld --with-gnu-as
--with-as=/opt/local/lang/gcc331-sol7/bin/as --with-cpu=supersparc --disable-nls
--disable-multilib --enable-languages=all --enable-c99
Thread model: single
gcc version 3.3.1
--
Summary: Can't assign a predefined const int 0 to a pointer
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: warp at iki dot fi
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: sparc-sun-solaris2.7
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13980