Crossware

Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->Converting a C Project to C++

The compiler will automatically compile any source file with a .CPP extension as C++.  Therefore to convert an existing project from C to C++, change the extensions of all of the .C source files to .CPP (except for XSTDSYS.C which is called from startup.asm assuming the C naming convention).

If your source files include any interrupt handlers, then you should designate them as C functions using the extern C syntax.  For instance:

extern C void _interrupt MyInterruptHandler
{
}

Also if you have included alternatives to the C library functions in your program (such as putch() and getch()) then these also need to be designated as C functions in a similar way.
    
Finally if you have any global objects that need to be constructed and/or destroyed, then you need to add two calls to startup.asm.  The library routine __initobjects will call the constructors and the library routine __termobjects will call the destructors.  These calls need to be added before and after the call to main as follows:

    extern    __initobjects
    bl    __initobjects    ; call the constructors of the global objects
    bl    _main
_exit
    extern    __termobjects
    bl    __termobjects    ; call the destructors of the global objects
loop    b    loop