public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35669]  New: NULL (__null) not considered different from 0 with C++
@ 2008-03-22 20:06 l dot lunak at suse dot cz
  2008-03-22 21:11 ` [Bug c++/35669] " rguenth at gcc dot gnu dot org
                   ` (27 more replies)
  0 siblings, 28 replies; 29+ messages in thread
From: l dot lunak at suse dot cz @ 2008-03-22 20:06 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2493 bytes --]

When compiling with g++, the various error checking gained from using NULL
instead of plain 0 for the null pointer does not work. For example

$ cat a.c
#include <stdio.h>

void foo( int a )
    {
    printf( "INT\n" );
    }

int main()
    {
    foo( NULL );
    foo( 0 );
    int a = NULL;
    return 0;
    }

$ gcc -Wall a.c
a.c: In function ‘main’:
a.c:10: warning: passing argument 1 of ‘foo’ makes integer from pointer without
a cast
a.c:12: warning: initialization makes integer from pointer without a cast
a.c:12: warning: unused variable ‘a’

$ g++ -Wall a.c
a.c: In function ‘int main()’:
a.c:12: warning: unused variable ‘a’

As can be seen, compiling as C++ does not detect the mistakes in the code. The
compiler uses __null though, as can be seen in preprocessed code:

$ g++ -Wall -E a.c | tail
    {
    printf( "INT\n" );
    }

int main()
    {
    foo( __null );
    foo( 0 );
    int a = __null;
    }

$ gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --with-local-prefix=/usr/local
--infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib
--libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --with-slibdir=/lib
--with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --program-suffix=-4.3
--enable-version-specific-runtime-libs --enable-linux-futex
--without-system-libunwind --with-cpu=generic --build=i586-suse-linux
Thread model: posix
gcc version 4.3.0 (SUSE Linux)

The problem already exists with gcc 4.2.1, but gcc 4.1.2 (specifically "gcc
version 4.1.2 20070115 (prerelease) (SUSE Linux)") works fine and reports:

$ g++ -Wall a.c
a.c: In function ‘int main()’:
a.c:10: warning: passing NULL to non-pointer argument 1 of ‘void foo(int)’
a.c:12: warning: converting to non-pointer type ‘int’ from NULL
a.c:12: warning: unused variable ‘a’


-- 
           Summary: NULL (__null) not considered different from 0 with C++
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: l dot lunak at suse dot cz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2010-02-20 23:51 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-22 20:06 [Bug c++/35669] New: NULL (__null) not considered different from 0 with C++ l dot lunak at suse dot cz
2008-03-22 21:11 ` [Bug c++/35669] " rguenth at gcc dot gnu dot org
2008-03-22 23:16 ` l dot lunak at suse dot cz
2008-03-23 14:08 ` manu at gcc dot gnu dot org
2008-03-23 19:00 ` truedfx at gentoo dot org
2008-03-23 19:44 ` manu at gcc dot gnu dot org
2008-03-23 20:16 ` l dot lunak at suse dot cz
2008-03-23 22:18 ` manu at gcc dot gnu dot org
2009-02-12 17:57 ` peter at cordes dot ca
2009-04-28 20:01 ` mdorey at bluearc dot com
2009-04-29 12:51 ` bangerth at gmail dot com
2009-04-29 13:22 ` l dot lunak at suse dot cz
2009-04-29 16:47 ` mdorey at bluearc dot com
2009-12-08 10:49 ` redi at gcc dot gnu dot org
2009-12-21 20:02 ` mdorey at bluearc dot com
2009-12-22 10:36 ` jwakely dot gcc at gmail dot com
2009-12-22 18:12 ` mdorey at bluearc dot com
2010-02-14 20:19 ` manu at gcc dot gnu dot org
2010-02-14 21:47 ` l dot lunak at suse dot cz
2010-02-14 22:06 ` manu at gcc dot gnu dot org
2010-02-16 17:11 ` jason at gcc dot gnu dot org
2010-02-16 18:02 ` echristo at apple dot com
2010-02-16 18:06 ` manu at gcc dot gnu dot org
2010-02-16 18:09 ` echristo at apple dot com
2010-02-16 18:27 ` manu at gcc dot gnu dot org
2010-02-16 18:43 ` jason at redhat dot com
2010-02-20 21:32 ` manu at gcc dot gnu dot org
2010-02-20 21:38 ` manu at gcc dot gnu dot org
2010-02-20 23:51 ` jason at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).