public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gdr at integrable-solutions dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/22485] pointer +- integer is never NULL Date: Fri, 15 Jul 2005 08:26:00 -0000 [thread overview] Message-ID: <20050715081009.15468.qmail@sourceware.org> (raw) In-Reply-To: <20050714131031.22485.mattias@virtutech.se> ------- Additional Comments From gdr at integrable-solutions dot net 2005-07-15 08:10 ------- Subject: Re: pointer +- integer is never NULL "falk at debian dot org" <gcc-bugzilla@gcc.gnu.org> writes: | ------- 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" <gcc-bugzilla@gcc.gnu.org> 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<int*>(0) + 5 undefined. | | Sorry, I cannot follow you. I'd find it massively unsurprising if | reinterpret_cast<int*>(0) produces a null pointer, and if I then get | undefined behavior for doing something with it that is undefined for a | null pointer. But, if I used reinterpret_cast to turn an integer value 0 into a pointer, there is no reason why the compiler would assume that I do not know the underlying machine and what I'm doing with the pointer. | In fact I'd find it very *surprising* if | reinterpret_cast<int*>(0) behaves different than a normally | constructed null pointer anywhere. At least, you get that part of my indirect observation! :-) | > 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. if follows from your surprise that reinterpret_cast<int*> does something different from the null pointer constant (int*)0. | As it seems, arguing with different levels of surprisingness seems to | be somewhat subjective, so I don't think this leads us anywhere. I'm not actually arguing on different level of surprisingness. I'm just looking at reinterpret_cast and its implication. | > 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*, ^^^^^^^^^^^ For the offsetof *macro*, yes But that is not the case for codes that uses reinterpret_cat<int*>(expr), where expr is an integer expression with value 0. Scanning a region of memory starting from zero, is not exactly the kind of thing never done in practice. | which we could easily avoid to tag as non-null. so you would have to pretend that a null pointer constant is not null? That is even more bizarre arithmetic. -- Gaby -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22485
next prev parent reply other threads:[~2005-07-15 8:10 UTC|newest] Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-07-14 13:10 [Bug c/22485] New: " mattias at virtutech dot se 2005-07-14 13:14 ` [Bug c/22485] " mattias at virtutech dot se 2005-07-14 13:14 ` pinskia at gcc dot gnu dot org 2005-07-14 13:19 ` falk at debian dot org 2005-07-14 13:45 ` dberlin at gcc dot gnu dot org 2005-07-14 13:46 ` falk at debian dot org 2005-07-14 15:19 ` gdr at integrable-solutions dot net 2005-07-14 15:21 ` gdr at integrable-solutions dot net 2005-07-14 16:03 ` falk at debian dot org 2005-07-14 19:38 ` Gabriel Dos Reis 2005-07-14 21:47 ` Falk Hueffner 2005-07-14 19:40 ` gdr at integrable-solutions dot net 2005-07-14 22:19 ` falk at debian dot org 2005-07-14 23:04 ` gdr at integrable-solutions dot net 2005-07-15 7:51 ` falk at debian dot org 2005-07-15 8:26 ` gdr at integrable-solutions dot net [this message] 2005-07-15 9:27 ` mattias at virtutech dot se 2005-07-15 10:35 ` gdr at integrable-solutions dot net 2005-07-15 11:42 ` pluto at agmk dot net 2005-07-15 14:25 ` falk at debian dot org 2005-07-15 15:02 ` gdr at integrable-solutions dot net 2005-07-15 15:21 ` falk at debian dot org 2005-07-15 15:54 ` mattias at virtutech dot se 2005-09-24 5:37 ` gdr at gcc dot gnu dot org 2005-09-24 9:39 ` falk at debian dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050715081009.15468.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).