This is the mail archive of the gcc-patches@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]

Re: fixincludes of C++ friendly NULLs


On Oct 27, 2004, at 2:34 AM, Nathan Sidwell wrote:

Mike Stump wrote:

This patch fixes the fixincluding of C++ friendly NULLs...



+ /* avoid changing C++ friendly NULL */
+ bypass = __cplusplus;
select = "^#[ \t]*define[ \t]+NULL[ \t]+\\(\\(void[ \t]*\\*\\)0\\)";
c_fix = format;
c_fix_arg = "#define NULL 0";



I don't understand, isn't this fix changing a C++ unfriendly NULL to a C++ friendly one? What is the bug being fixed?

The standard definition of NULL is (from stdlib.h):


#ifndef NULL
#ifdef __GNUG__
#define NULL __null
#else /* ! __GNUG__ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else /* __cplusplus */
#define NULL 0
#endif /* ! __cplusplus */
#endif /* __GNUG__ */
#endif /* ! NULL */

On some systems, they've _fixed_ their header files to be C++ safe. The above, if a good definition for a C++ safe version of NULL. The problem will fixincludes, is that it _fixes_ the above correct code, to be incorrect:

#ifndef NULL
#ifdef __GNUG__
#define NULL __null
#else /* ! __GNUG__ */
#ifndef __cplusplus
#define NULL 0
#else /* __cplusplus */
#define NULL 0
#endif /* ! __cplusplus */
#endif /* __GNUG__ */
#endif /* ! NULL */

This is wrong. By avoiding fixing any file that is C++ safe, we preserve the goodness of the original file. If there is no C++ goodness in the file, only thjen do we allow it to clobber things.



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