#if defined(__cplusplus)
Extern “C”
#endif
This method is always used in C style head file, because when you had wrote
some c style codes, and these functions will be called in C++ files. You
should add this snippet in your c style head file. Because when the C++
files be compiling, the C++ compiler will working and the __cplusplus will
be defined.
But when you call a C++ function in a C file ,the working compiler is a C
compiler, so the __cplusplus will not be defined. So the extern “C” will not
be used in your temp.h file.
now I tell you some rules,
When you want to call C functions in C++ files, you can used as follow:
//1.c
Void fun1()
{
…
}
Void fun2()
{
…
}
//1.h
#pragma once
#ifdef __cplusplus
extern “C”{
#endif
Void fun1();
Void fun2();
#ifdef __cplusplus
}
#endif
//2.cpp
#include 1.h
void Testfun()
{
Fun1();
}
When you want to call C++ functions in C file, you can as follows:
//1.cpp
extern "C"Void fun1()
{
…
}
extern “C” void fun2()
{
…
}
//You alse can use this way
Extern “C”{
Void fun1()
{
…
}
Void fun2()
{
…
}
}
//1.h
#pragma once
Void fun1();
Void fun2();
//2.c
#Include “1.h”
Void Testfun()
{
fun1();
fun2();
}
/////////////////////////////////////
RE: Re:[ntdev] Mixing C and C++ files in a driver project.
Thought I might need to add that when I posted originally:
In temp.h:
#if defined(__cplusplus)
Extern “C”
#endif
Temp(void);
The constant name is described in the compiler documentation- compiler
defines it when a C++ file is being processed, so you can use a header for
both languages.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer