FAQ: How can you use a C-function, defined in a separate file, in a method of a C++-class?

Document created by mue on Apr 13, 2009Last modified by CraigG on Nov 12, 2013
Version 2Show Document
  • View in full screen mode

Q:

How can you use a C-function, defined in a separate file, in a method of a C++-class?

 

----------

 

A:

By declaring the C-function as extern "C", the C-compiler will know that it is an externally declared function and that it is exists in the C-scope of memory.

 

Example:

 

Contents of func.c-file:

 

int func(void)

{

     /* My function */

}

 

 

In your C++-file your declare the external function func() as:

 

extern "C" int func(void);

 

----------

 

This FAQ was generated from the following thread: How can you use a C-function, defined in a separate file, in a method of a C++-class?

Attachments

    Outcomes