Post Go back to editing

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

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

Parents
  • ColinJ wrote:

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

    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);

Reply
  • ColinJ wrote:

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

    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);

Children
No Data