Search code examples
c++ooparmcross-compiling

derived class with no implementation file (.cpp)


In project I've inherited from coworker, I have base c++ class with header and implementation. For the sake of understanding, I will provide example situation, because the code itself is too big: bthidtransport.h:

class BtHidTransport
{
public:
    BtHidTransport();    // constructor

protected:
    virtual ~BtHidTransport();   // destructor
}    // BtHidTransport

bthidtransport.cpp:

BtHidTransport::BtHidTransport
{
}   // constructor

BtHidTransport::~BtHidTransport()
{
}   // destructor

This is base class, now we have derived class header:
bthidtransportfixes.h:

#include "bthidtransport.h"

class BtHidTransportFixes : public BtHidTransport
{
    BtHidTransportFixes(); // constructor
    virtual ~BtHidTransportFixes();    // destructor
}   // BtHidTransportFixes

However, in particular project, BtHidTransportFixes has no implementation (.cpp) file. The project itself builds without errors. If I instantiate new object at runtime from class with:

BtHidTransport* createdObject=new BtHidTransportFixes();

and BtHidTransportFixes has no implementation (.cpp) file, what is the order of execution in terms to parent class? I am using Eclipse 4.3.2 for Windows (host OS is Windows 7 64bit Ultimate) with ARM DS-5 5.20.2 compiler. There is no implementation of BtHidTransportFixes anywhere in the project, I've searched for it in ALL projects files. Compiler optimizations are turned off with -O0 flags explicitly. Here is assembler listing of build process:

;;;107        // Create the BT transport first
;;;108        BtHidTransport *btTransport = new BtHidTransportFixes();
00002a  2088              MOVS     r0,#0x88
00002c  f7fffffe          BL       _ZN16StartupAllocatednwEj ; StartupAllocated::operator new(unsigned)
000030  4934              LDR      r1,|L1.260|
000032  2200              MOVS     r2,#0
000034  9100              STR      r1,[sp,#0]
000036  4b34              LDR      r3,|L1.264|
000038  4611              MOV      r1,r2
00003a  f7fffffe          BL       _ZN19BtHidTransportFixesC1EP9BtHidConnP13BtPairingListPK14tBTM_APPL_INFOPK23tBTM_LINK_EVT_CALLBACKS ; BtHidTransportFixes::BtHidTransportFixes()
00003e  4604              MOV      r4,r0

and linker ouput:

Stack Usage for BtHidTransportFixes::BtHidTransportFixes() 0x0 bytes.
Stack Usage for BtHidTransportFixes::BtHidTransportFixes() 0x0 bytes.
Stack Usage for BtHidTransportFixes::BtHidTransportFixes__sub_object() unknown bytes.
BtHidTransportFixes::BtHidTransportFixes() 0x0020587d   Thumb Code     0  20730_ram_ext.symdefs ABSOLUTE
    BtHidTransportFixes::BtHidTransportFixes__sub_object() 0x0020587d   Thumb Code     0  20730_ram_ext.symd

The size of constructor seems to be 0, what exaclty is executed here? And to simplify out, I've deliberately deleted parameters of constructor (here, in StackOverflow description of issue), is this my bad?


Solution

  • I have found a solution to particular issue. Build process file (.inc) is instructed to replace header file bthidtransportfixes.h with patched bthidtransportfixes.h, which was not included in project tree itself, but resided in Windows User Home Directory and then the missing code itself is copied from patched header to original. If I clean project, the operation is reversed. What a bunch of nonsense, this project is heavily messed up! Here is missing constructor code, taken from patch:

    BtHidTransportFixes::BtHidTransportFixes(BtHidConn            *btHidConn, 
                                             BtPairingList        *hostList, 
                                             const tBTM_APPL_INFO *btmSecCallbacks,
                                             const tBTM_LINK_EVT_CALLBACKS *btmLinkEvtCb) :
        BtHidTransport(btHidConn, hostList, btmSecCallbacks, btmLinkEvtCb)
    {
        #ifdef PROXIMITY_ASSOCIATION_SUPPORT
            // Initialize the observer to NULL
            proxAssocObserver.pObj = NULL;
        #endif
        #ifdef FIX_NEED_DISCOVERYLED_TICK
            discoveryTickEnabled = hidAppConfig.discoveryLedEnabled;
    
            discoveryTickBasePeriodInMs = 50;
        #endif
    
        #ifdef FIX_CQ_911035
            ucdConnectRequested = FALSE;
        #endif
    }
    

    I have created implementation file myself, add it to project, put the patched code in it, remove .inc command to include patch, added newly implementation file to build process and it works now like a charm.