Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #86038

Re: Is it possible to test if a raw pointer is pointing to a valid object?

Path csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Is it possible to test if a raw pointer is pointing to a valid object?
Date Wed, 24 Aug 2022 10:44:03 -0700
Organization None to speak of
Lines 43
Message-ID <874jy1y1ss.fsf@nosuchdomain.example.com> (permalink)
References <te5lf8$3camt$1@dont-email.me> <te5mrp$3ceup$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Info reader01.eternal-september.org; posting-host="ba7b50a2a22d5fe194a1cea15d08e5dc"; logging-data="3554886"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+A9hy/iJ9T2zmdDWlhIHLz"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock sha1:5TIOi3e7ScmJYrEU7QP7eZPd0k8= sha1:c48uKlje7D3vS0X5S0dtFxXHW8E=
Xref csiph.com comp.lang.c++:86038

Show key headers only | View raw


Paavo Helde <eesnimi@osa.pri.ee> writes:
> 24.08.2022 20:00 JiiPee kirjutas:
>> First the code. The question below it:
>> ------------------------
>> class Parent
>> {
>> public:
>>      void foo2() {}
>> };
>> class Child
>> {
>> public:
>>      Parent* m_parent{nullptr};
>>      void foo() {
>>          // can the validity of the raw pointer m_parent be checked?
>>          m_parent->foo2();
>>      }
>> };
>> void main()
>> {
>>      Parent* parent = new Parent;
>>      Child child;
>>      child.m_parent = parent;
>>      delete parent;
>>      child.foo(); // any way this call knowing parent is now deleted?
>
> No, there isn't any way. At best you can check if a pointer points to
> memory page which is readable or writable for the process, but that
> does not help much.

There's no portable way to do even that.

[...]

> void main()

Of course main returns int, not void.  (I know that was in the parent
article.)

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 20:00 +0300
  Re: Is it possible to test if a raw pointer is pointing to a valid object? Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 20:24 +0300
    Re: Is it possible to test if a raw pointer is pointing to a valid object? Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 20:28 +0300
    Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 20:39 +0300
    Re: Is it possible to test if a raw pointer is pointing to a valid object? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-24 10:44 -0700
      Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 20:51 +0300
        Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 20:52 +0300
          Re: Is it possible to test if a raw pointer is pointing to a valid object? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-24 11:59 -0700
            Re: Is it possible to test if a raw pointer is pointing to a valid object? Manfred <noname@add.invalid> - 2022-08-26 02:26 +0200
  Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 20:41 +0300
    Re: Is it possible to test if a raw pointer is pointing to a valid object? Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2022-08-24 13:51 -0600
  Re: Is it possible to test if a raw pointer is pointing to a valid object? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-24 12:45 -0700
    Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-24 23:17 +0300
      Re: Is it possible to test if a raw pointer is pointing to a valid object? scott@slp53.sl.home (Scott Lurndal) - 2022-08-24 20:54 +0000
        Re: Is it possible to test if a raw pointer is pointing to a valid object? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-24 14:57 -0700
          Re: Is it possible to test if a raw pointer is pointing to a valid object? Vir Campestris <vir.campestris@invalid.invalid> - 2022-08-25 12:52 +0100
  Re: Is it possible to test if a raw pointer is pointing to a valid         object? Sam <sam@email-scan.com> - 2022-08-24 20:21 -0400
  Re: Is it possible to test if a raw pointer is pointing to a valid object? Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-25 07:39 +0200
    Re: Is it possible to test if a raw pointer is pointing to a valid object? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 03:37 -0700
      Re: Is it possible to test if a raw pointer is pointing to a valid         object? Sam <sam@email-scan.com> - 2022-08-25 09:37 -0400
      Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-25 17:28 +0300
        Re: Is it possible to test if a raw pointer is pointing to a valid         object? Sam <sam@email-scan.com> - 2022-08-25 19:39 -0400
        Re: Is it possible to test if a raw pointer is pointing to a valid object? Paul N <gw7rib@aol.com> - 2022-08-26 05:49 -0700
          Re: Is it possible to test if a raw pointer is pointing to a valid object? JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-08-26 19:35 +0300
            Re: Is it possible to test if a raw pointer is pointing to a valid object? Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2022-08-26 12:25 -0600
      Re: Is it possible to test if a raw pointer is pointing to a valid object? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-25 11:38 -0700
  Re: Is it possible to test if a raw pointer is pointing to a valid object? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-26 16:08 -0500

csiph-web