Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
126 views

Function templates are not allowed to have C language linkage: extern "C" { template<typename T> // error: template with C linkage void bad_f() {} } This is reasonable, as ...
yuri kilochek's user avatar
5 votes
1 answer
148 views

Both GCC and Clang reject extern "C" static void foo() {} but accept extern "C" { static void foo() {} } Aren't these supposed to be equivalent?
yuri kilochek's user avatar
-2 votes
1 answer
147 views

I am working on a personal project where I need to intercept Linux APIs like open(), read() etc, and I would like to do some data analysis on them. I would need to keep a C++ data structure std::map ...
Aravind A's user avatar
  • 476
0 votes
4 answers
290 views

Say I have a C header file a.h Any C++ header file, say a.hpp that #includes a.h, should do so in an extern "C" block. So I have some header files that are common between our C++ code and C ...
John Carter's user avatar
0 votes
2 answers
176 views

I have created a simple C library is generated by one .c and one .h file. // test.c #include "test.h" #include "stdlib.h" void GetArray(int * array) { array = (int *) calloc(2, ...
Tucker's user avatar
  • 101
-1 votes
1 answer
587 views

I'm working on a shared library and adding some functions which I export as c functions, so I can use them easily in C#. But none of my c functions are exported. According to the app DependenciesGUI ...
Tohrwarneth's user avatar
1 vote
1 answer
163 views

If a variable is declared somewhere without extern "C" (e.g. in a header file) and afterwards defined with extern "C", then the Visual C++ compiler compiles it with C++ linkage ...
MattTT's user avatar
  • 607
2 votes
2 answers
133 views

In my header file, foo.h, I have: #ifdef __cplusplus extern "C" { #endif int foo(int x); #ifdef __cplusplus } #endif Now, in foo.cpp, should I also use extern "C", and define: #...
einpoklum's user avatar
  • 137k
-1 votes
1 answer
90 views

The reproduceable error code is: #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> //#include <...
Himanshu's user avatar
0 votes
1 answer
92 views

I have a source code structured as follows foo.h (header from c library) #pragma once struct foo {...}; bar.h #pragma once extern "C" { #include "foo.h" } class Bar { foo val;...
Roman's user avatar
  • 1,466
2 votes
1 answer
228 views

I want to write a templated function and explicitly instantiate it inside extern "C" block to avoid code duplication. Here is example of what I mean: template<typename T> // my ...
Gleb's user avatar
  • 43
3 votes
2 answers
299 views

Consider the following translation unit: extern "C" int x = 1; I know that C-mangling an int doesn't mean much; and that int x = 1 already guarantees external linkage, but this should work. ...
einpoklum's user avatar
  • 137k
0 votes
0 answers
182 views

In C++, can I check whether a certain function has been declared "extern C" or not? I don't mind checks restricted to the current translation unit. I'd like to check this at compile-time, ...
einpoklum's user avatar
  • 137k
2 votes
3 answers
1k views

I am writing a c wrapper around a c++ library. In the c++ there are enum classes used as types for function arguments. How do I use theme correctly in the c header. One ugly way would be to use int's ...
ludw's user avatar
  • 123
7 votes
3 answers
3k views

I'm writing a C library, which may potentially be useful to people writing C++. It has a header which looks like this: #ifndef FOO_H_ #define FOO_H_ #include <bar.h> #include <stdarg.h> #...
einpoklum's user avatar
  • 137k
0 votes
1 answer
161 views

I wanted to know how widely used is the mixing of C++ and C. I mean as in using of C libraries/functions and call it in C++ program like how it is done here Mix C with C++. How extensive is its use in ...
Anzo Sasuke's user avatar
1 vote
0 answers
61 views

The following code compiles with gcc but does not compile with MSVC (Godbolt link) #include <array> extern "C" std::array<float,3> foo() { return std::array<float,3>{1,...
Anonymous's user avatar
1 vote
1 answer
223 views

This code: #include <stdlib.h> // int abs(int); int abs(int i = 0) { return 42; } int main() { return abs(1); // Returns 42 } Returns 42. The compiler picks the overloaded C++ function. I ...
braph's user avatar
  • 23
7 votes
2 answers
264 views

Suppose I'm using some C library which has a function: int foo(char* str); and I know for a fact that foo() does not modify the memory pointed to by str. It's just poorly written and doesn't bother ...
einpoklum's user avatar
  • 137k
0 votes
0 answers
1k views

I´ve got an extern DLL to work with. I try to load the DLL with LoadLibrary and get the function by calling GetProcAddress but everytime I debug the programm I got an exception, which I can ignore by ...
Felix Arnold's user avatar
2 votes
1 answer
320 views

I was writing my own std::thread-like wrapper for pthread_* functions (for educational purposes). The constructor I came up with looked like this: template<class Fn, class... Args> explicit ...
Evg's user avatar
  • 26.6k
3 votes
1 answer
865 views

I am very curious about what happens during linking, and, during my research in this area I have stabbed upon this code #ifdef __cplusplus extern “C” { #endif extern double reciprocal (int i); #...
MinuxLint's user avatar
  • 141
0 votes
2 answers
153 views

I've got a class named tmc, which now contains (among other things, which are not relevant here) a private constructor, a static factory method, and an instance method named ReadLoop (void*): extern "...
Neppomuk's user avatar
  • 1,222
4 votes
4 answers
3k views

I know when i want to link C code as C code in C++ should i use extern "C". But with the following code : /* file.h */ some (void) { return 10; } extern "C" { #include "file.h" } #include <...
Ghasem Ramezani's user avatar
4 votes
1 answer
435 views

Is this code correct? extern "C" extern int x; // 1 extern extern "C" int y; // 2 extern "C" extern "C" int z; // 3 int main() { } gcc rejects 1 and 2 as syntax errors and accepts 3. ...
M.M's user avatar
  • 143k
7 votes
1 answer
965 views

I have the following function: class Foo; template <typename T> struct PyArray1D{ std::size_t size; T *array; }; extern "C" PyArray1D<Foo> SimulatePhotonEvents() { Foo * ...
Frank's user avatar
  • 2,788
3 votes
1 answer
883 views

I have a function that is located in a shared object, and is loaded and executed with dlsym from the main program. (both the shared object and the main program are C++) Is it possible that this ...
Guy's user avatar
  • 35
0 votes
2 answers
73 views

Just wondering if anyone can give me some advice regarding where I'm going wrong here. My program works OK if I run it as is, but as soon as I swap the commented line with the one below it, I get ...
Wade Shiell's user avatar
3 votes
2 answers
1k views

I'm comparing Numerical Recipes four1.c to Nayuki's FFT. Both are the C versions, but I'm using a C++ driver. For the comparison, I'm compiling (or more appropriately, linking) both into an executable ...
KyleG's user avatar
  • 143
3 votes
2 answers
236 views

I'm trying to write a C++ library that can be called from C. However, whenever I try to even write a bare minimum example, it crashes with undefined references. Here is my code: mylibrary.h #ifndef ...
Griffort's user avatar
  • 1,315
0 votes
0 answers
56 views

So I want to use string class and multiset template of C++. My original code interfaces from Python to C using ctypes and now I am trying to interface C to C++. (If there is any direct interfacing ...
user avatar
0 votes
1 answer
181 views

We have a plugin system that calls functions in dlls (user-generated plugins) by dlopening/LoadLibrarying the dll/so/dylib and then dlsyming/GetProcAddressing the function, and then storing that ...
Philipp's user avatar
  • 987
0 votes
1 answer
495 views

I'm trying to build a WIN32 console app that uses the current 2.12.28 ftd2xx.lib static library from FTDI. I'm using VS2013 and native unmanaged C++. My call looks like this. #include "../ftd2xx.h" ...
JonN's user avatar
  • 2,588
4 votes
1 answer
1k views

I'm using Lapack in my C++ code. I'm quite confused how to properly link to the library. Here is a small example corresponding to my code calling a function from Lapack: #include <iostream> ...
Caduchon's user avatar
  • 5,278
2 votes
5 answers
786 views

I'm new to mixing C & C++ code. Understood the need of extern & __cplusplus directives after reading some SO links & online reading. Not sure why am I getting the error. Did i miss ...
codeLover's user avatar
  • 3,860
4 votes
0 answers
400 views

Following code is accepted by gcc 6 and clang 4, but MSVC 2017 which claims to support C++14 (and generic lambdas in particular) discards it with error C2894: templates cannot be declared to have 'C' ...
rafalc's user avatar
  • 202
0 votes
2 answers
98 views

Is it pointless to have: #ifdef __cplusplus extern "C" { #endif // code... #ifdef __cplusplus } #endif Where "code..." is just a bunch of defines and typedefs (no includes, etc.)?
flmng0's user avatar
  • 447
0 votes
0 answers
332 views

I have a bridge between unity 3d and iOS to pass data. I can sent data successfully from unity 3d to my iOS using extern "C", then i can call a objective c method from a method of extern "c". But from ...
Nuibb's user avatar
  • 1,860
1 vote
2 answers
2k views

If I use clang 3.8.1 to compile: extern "C" { int foo(int x) { register int y = x; return y; } } int main() { return foo(123); } I get the warning: a.cpp:3:18: warning: 'register' storage ...
einpoklum's user avatar
  • 137k
-1 votes
1 answer
506 views

MS Visual Studio 2008. This seems to be a name mangling issue, but I can't find the right search terms to come up with an answer. I have a dynamic lib that has a class in it, which is using a logging ...
JoeFish's user avatar
  • 3,109
2 votes
2 answers
121 views

Basically I am wondering whether something like f(const void* a){ // This is also what `(char**) a` would do behind the scenes char** string_a_ptr {reinterpret_cast<char**>(const_cast<...
maow's user avatar
  • 2,897
2 votes
0 answers
521 views

I'm trying to utilize a C++ library in Modelica. Modelica compilers generate c from Modelica source and then invokes a c compiler to create an executable. Modelica provides a mechanism to call c ...
Adam's user avatar
  • 67
4 votes
1 answer
455 views

I have some C code being called from C++. The header resembles the following: #ifndef CLibH #define CLibH #ifdef __cplusplus extern "C" { #endif //C API void foo(void); // ... #ifdef __cplusplus ...
Trevor Hickey's user avatar
11 votes
4 answers
11k views

I'm writing a C++ shared library for a C program to use. However, I have a question about extern and extern "C". Consider the following code My header file is like this: #ifdef __cplusplus ...
Thenewstockton's user avatar
3 votes
2 answers
3k views

Given this code: A2.H _declspec(dllimport) void SomeFunc(); struct Foo { Foo(); ~Foo(); }; inline Foo::Foo() { } inline Foo::~Foo() { SomeFunc(); } A1.H #include "A2.h" extern "C" ...
ForeverLearning's user avatar
1 vote
1 answer
227 views

Environment is Microsoft Visual C++ 2015 and Windows 7. Is there anything special about inline extern "C" functions defined in a header? I am consuming an SDK in which one of the headers contain such ...
ForeverLearning's user avatar
0 votes
3 answers
606 views

I have a C-function called "count" that looks like this: void count(){ static int c = 0; printf("Counter=%i", c); c++; } Futhermore I have a vector of Cpp-objects and each object calls the "...
Miyako's user avatar
  • 9
3 votes
0 answers
2k views

I have a simple c++ Visual Studio project: #include "test.h" test::test() { } test::~test() { } HEADER: #pragma once #include <string> class test { public: test(); ~test(); }; When I ...
PatMac's user avatar
  • 79
7 votes
2 answers
848 views

I have a C library that uses a struct of function pointers for callbacks. The callbacks will be called from C code. extern "C" { typedef struct callbacks_t { void (*foo) (const char*); int (*...
user1526370's user avatar
9 votes
4 answers
6k views

In order to use C++ code in a C file, I read that we can just do extern "C" { (where the c++ code goes here)}, but when I try printing something out using cout, I keep getting an error because it does ...
Sandra Delatorre's user avatar