Hi,

I want to use a function from a different file in the main method of another file. Both the files are in the same visual studio project. I used the extern "C" keyword in the foreward declaration of this external function in the file containing the main method but its not working?

How do I do it?
Thanks...

You only need the extern "C" if you're mixing C and C++.
If it's all C++, then extern should be fine.

Post actual code and error messages if you're still stuck.

Does extern "c" work only for C Codes. This is because i read in a book that with extern "c" we can export many codes from Many Languages.

> Does extern "c" work only for C
yes, and only with c capitalized. extern "C" ... however, an implementation can support linkage to other languages. eg. extern "FORTRAN" ...

7.5 - Linkage specifications [dcl.link]
-2- The string-literal indicates the required language linkage. The meaning of the string-literal is implementation-defined. ... When the string-literal in a linkage-specification names a programming language, the spelling of the programming language's name is implementation-defined. [Note: it is recommended that the spelling be taken from the document defining that language, for example Ada (not ADA) and Fortran or FORTRAN (depending on the vintage). The semantics of a language linkage other than C++ or C are implementation-defined. ]

-3- Every implementation shall provide for linkage to functions written in the C programming language, "C" .... [Example:
complex sqrt(complex); // C++ linkage by default
extern "C" {
double sqrt(double); // C linkage
}
--- end example] - ISO/IEC 14882 : 1998(E)

This article has been dead for over six months. Start a new discussion instead.