extern-c Questions

2

Solved

As it is known, declaring extern "C" to C++ function makes its name have C linkage, enabling C code to link. My question is - are there other programming languages we can make C++ function names h...
Gonophore asked 31/1, 2014 at 16:3

18

Solved

What exactly does putting extern "C" into C++ code do? For example: extern "C" { void foo(); }
Legation asked 25/6, 2009 at 2:10

1

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 ...
Kenric asked 9/6, 2023 at 6:45

2

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 bothe...
Phyte asked 10/11, 2020 at 9:38

0

I'm was writing some interfacing code to call c++ routines from fortran which is why I dumped the methods into an extern "C" block. When compiling with g++.exe (x86_64-win32-seh-rev1, Built by MinG...
Idaidae asked 4/5, 2020 at 20:56

1

I have the following function: class Foo; template <typename T> struct PyArray1D{ std::size_t size; T *array; }; extern "C" PyArray1D<Foo> SimulatePhotonEvents() { Foo * foo = ne...
Buttermilk asked 9/8, 2019 at 11:26

11

Solved

Why do we need to use: extern "C" { #include <foo.h> } Specifically: When should we use it? What is happening at the compiler/linker level that requires us to use it? How in terms of c...
Arrowwood asked 15/9, 2008 at 23:19

4

Solved

I'm working on a project that has a lot of legacy C code. We've started writing in C++, with the intent to eventually convert the legacy code, as well. I'm a little confused about how the C and C++...
Inadmissible asked 24/9, 2010 at 17:3

6

Solved

I know this. Calling C function from C++: If my application was in C++ and I had to call functions from a library written in C. Then I would have used //main.cpp extern "C" void C_library_func...
Peery asked 30/4, 2010 at 11:36

4

Solved

I have a C function that I would like to call from C++. I couldn't use "extern "C" void foo()" kind of approach because the C function failed to be compiled using g++. But it compiles fine using gc...
Swinson asked 31/5, 2013 at 6:27

4

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 ext...
Lugubrious asked 1/7, 2016 at 9:6

2

Solved

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 (*bar...
Calcification asked 29/4, 2016 at 15:10

4

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 d...
Agram asked 22/4, 2016 at 4:57

9

Solved

I had an interview recently and one question asked was what is the use of extern "C" in C++ code. I replied that it is to use C functions in C++ code as C doesn't use name-mangling. I was asked why...
Wilkens asked 14/4, 2016 at 11:34

2

Solved

I frequently come across C header files that contain extern "C" guards, but don't contain any actual functions. For example: /* b_ptrdiff.h - base type ptrdiff_t definition header */ #ifndef __I...
Etamine asked 4/11, 2015 at 16:2

1

Solved

I have a cpp code in which I want to call a c function. Both compile well to .o files, but when the clang++ is executing for compilation, I receive the following error: file.cpp:74:12: error: expe...
Architectonics asked 25/5, 2015 at 14:14

6

Solved

I wrote a C++ function that I need to call from a C program. To make it callable from C, I specified extern "C" on the function declaration. I then compiled the C++ code, but the compiler (Dignus S...
Obeded asked 4/9, 2009 at 18:30

3

Solved

I have seen C/C++ code using extern "C" declared in function signatures and also while including a C header into a CPP file. but some functions just declare extern before their signature(wit...
Pollinosis asked 20/1, 2015 at 14:51

4

Solved

I've got C++ functions that I want to declare using extern "C" even though they are only called in C++ code. Yes, I know this is strange but it's something I would like to do for consistency since ...
Chorister asked 6/4, 2013 at 0:31

2

Solved

I want to pass the pointer of an instance of a function template to a C function as callback. It's obviously impossible to declare the template as extern "C". Is it guaranteed that C++ us...
Threewheeler asked 8/3, 2014 at 17:34

5

Solved

What is the difference between a static member function and an extern "C" linkage function ? For instance, when using "makecontext" in C++, I need to pass a pointer to function. Google recommends u...
Ostrom asked 26/2, 2009 at 19:58

3

Solved

I want to have a plugin, with a simpler name to resolve in other C++ code. class B { }; extern "C" B foo(); // to avoid name mangling in order to be loaded by dlsym And in the other part of the...
Microcosm asked 27/1, 2013 at 15:35

3

Solved

From the C++11 draft, 7.5 (para. 1): Two function types with different language linkages are distinct types even if they are otherwise identical. So I can do overload based on language linkag...
Mutz asked 18/9, 2012 at 9:41

7

Solved

According to (c) ANSI ISO/IEC 14882:2003, page 127: Linkage specifications nest. When linkage specifications nest, the innermost one determines the language. A linkage specification does not est...
Michele asked 23/4, 2011 at 11:29

2

Solved

Why shouldn’t extern "C" be specified for a function that needs to be defined as a C function? What effect would that have on the compiler when compiling the file as a C source? If there is no eff...
Faenza asked 29/2, 2012 at 12:20

© 2022 - 2024 — McMap. All rights reserved.