From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29241 invoked by alias); 15 Jul 2005 06:41:48 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 29226 invoked by alias); 15 Jul 2005 06:41:44 -0000 Date: Fri, 15 Jul 2005 07:51:00 -0000 Message-ID: <20050715064144.29225.qmail@sourceware.org> From: "falk at debian dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050714131031.22485.mattias@virtutech.se> References: <20050714131031.22485.mattias@virtutech.se> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/22485] pointer +- integer is never NULL X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg01862.txt.bz2 List-Id: ------- Additional Comments From falk at debian dot org 2005-07-15 06:41 ------- Subject: Re: pointer +- integer is never NULL "gdr at integrable-solutions dot net" writes: > My indirect observation was that reinterpret_cast is intended for > specific needs that cannot adequately be expressed at the purely > object type level. The result is intended to be unsurprising to > those who know the addressing structure. Consequently it takes a > creative compiler to make reinterpret_cast(0) + 5 undefined. Sorry, I cannot follow you. I'd find it massively unsurprising if reinterpret_cast(0) produces a null pointer, and if I then get undefined behavior for doing something with it that is undefined for a null pointer. In fact I'd find it very *surprising* if reinterpret_cast(0) behaves different than a normally constructed null pointer anywhere. > Furthermore, given the mapping chosen by GCC, it takes even more > creative compiler to make (int *)0 + 5 also undefined. And I don't see how that follows, either. As it seems, arguing with different levels of surprisingness seems to be somewhat subjective, so I don't think this leads us anywhere. > There still are reasonable codes for system programming out there > that needs the to go through the play with null pointer -- we, GCC, > even used to distribute such things in the past. This is a more relevant point. I don't think this optimization would break offsetof-like macros, since they'd use null pointer *constants*, which we could easily avoid to tag as non-null. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22485