abraguez
abraguez

Reputation: 375

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

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?

Upvotes: 4

Views: 313

Answers (1)

R Sahu
R Sahu

Reputation: 206717

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.

Upvotes: 4

Related Questions