RosettaCodeData/Task/Use-another-language-to-call-a-function/C++/use-another-language-to-call-a-function-1.cpp

18 lines
392 B
C++
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
#include <string>
using std::string;
// C++ functions with extern "C" can get called from C.
extern "C" int
Query (char *Data, size_t *Length)
{
const string Message = "Here am I";
// Check that Message fits in Data.
if (*Length < Message.length())
return false; // C++ converts bool to int.
*Length = Message.length();
Message.copy(Data, *Length);
return true;
}