On Monday 29 June 2015 11:07:08 Dirk Hohndel wrote:
> Thanks Thiago for taking a look. It confused me that this would thrown a
> SIGSEGV in the pixel() function and not when dereferencing m_title to get
> to the pixel member function...

It wouldn't because pixel() is not a virtual function.

A non-virtual member function is just a regular function, called by name, 
which takes an implicit first parameter that is the object in question.

For 
        struct Foo { void f(); };
        Foo *foo;

The code
        foo->f();

is equivalent to
        _ZN3Foo1fEv(foo);

There's no pointer dereferencing before the actual call is placed, which is 
why it only crashed inside the function, not before it.

To be clear, it's undefined behaviour to do the above on foo = NULL. But UB can 
take many forms, including "working as expected".

There's some on-going discussion in the C++ standards group to allow the code

        f->foo();

to find a free function foo(Foo*) and call that. It's called "Unified call 
syntax" [1] and I actually triggered that discussion about a year and a half 
ago after seeing Linus rant here about some quirk of C++ :-)

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4474.pdf
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to