Is it possible to run C++ code inside an extern "C" block?

Viewed 149

For example

class demo {
public:
    static void printDemo(void)
    {
        std::cout << "Hi there" << std::endl;
    }
};

extern "C"{

void myInterrupt(void)
{
    demo::printDemo();
} 

}

Normally the extern "C" is for maintaining C-style linkage, so the declaration of myInterrupt matches the one in the interrupt vector declared in another file like startup.S, and the address of this function effectively gets installed in the vector.

But, does calling additional C++ functions inside of this block affect it?

1 Answers

Is it possible to run C++ code inside an extern ā€œCā€ block?

Yes.

The function has C interface in the sense that it can be called from a C program. But the implementation can contain C++ code.

But does calling additional c++ functions inside this block affects it?

No.

Related