This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13980] New: Can't assign a predefined const int 0 to a pointer


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]