473,795 Members | 3,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extern "C" and C++ files

These are the "restrictio ns" I have come accross when "wrapping up" all
function declarations in a header with extern "C":

i). Inability to overload functions in exposed API
ii). Inability to include (template?) classes (e.g. string) in exposed API

Are there other ex/implicit restrictions I may have missed ?

Jun 30 '07 #1
2 1385
Gray Alien wrote:
These are the "restrictio ns" I have come accross when "wrapping up" all
function declarations in a header with extern "C":

i). Inability to overload functions in exposed API
ii). Inability to include (template?) classes (e.g. string) in exposed API

Are there other ex/implicit restrictions I may have missed ?
I'd guess bool wouldn't be portably usable too? and one would assume
references can't be exposed to a C compiler either?

Alan
Jun 30 '07 #2
On Jun 30, 4:04 pm, Alan Woodland <a...@aber.ac.u kwrote:
Gray Alien wrote:
These are the "restrictio ns" I have come accross when "wrapping up" all
function declarations in a header with extern "C":
i). Inability to overload functions in exposed API
ii). Inability to include (template?) classes (e.g. string) in exposed API
Are there other ex/implicit restrictions I may have missed ?
I'd guess bool wouldn't be portably usable too? and one would assume
references can't be exposed to a C compiler either?
At the interface level, obviously, `extern "C"' doesn't make
much sense unless you stick to the common subset of C and C++.
(I would imagine that most, if not all, implementations , will
also make bool compatible with the C99 boolean type, and I can't
imagine an implementation where complex wasn't compatible with
it's C equivalents. But I don't think that the standards
guarantee this anywhere, and I'm not even sure how one would
formulate such guarantees.)

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5122
by: cppaddict | last post by:
In JNI header files generated by javah, what is going on with the 'extern "C"' which is inserted around the native method when "cplusplus" is defined. I would think you would only need extern "C" when cplusplus wasn't defined, ie, when you were using C and not C++. I want to implement my native methods in C++. Can I do this when they're wrapped by extern "C"? If so, what exactly is extern "C" doing?
111
6473
by: JKop | last post by:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances: 1) The whole "function declaration Vs object definition" fiasco, which results in the following (temporary creating) syntax: Blah poo = Blah();
2
3487
by: flyaflya | last post by:
I want use a c lib in vc6. so I use extern "C" to c function, include three files "test.cpp", "b.h" and "b.c": //************************************************ // test.cpp #include "stdafx.h" #include "b.h" int main(int argc, char* argv) {
8
2185
by: Generic Usenet Account | last post by:
Our C++ program was linked with some legacy C functions. We had used the extern "C" declaration, and everything was working fine. Then someone thought that it would be better to have a consistent file naming convention and renamed the files with the legacy C functions from .c to .cxx. Lo and behold we started getting linker errors left and right. When we reverted back to the old naming convention, the problem went away. Also, the...
4
2766
by: cpptutor2000 | last post by:
Could some C++ guru help me please? I am trying to build an application using gcc 3.2.3, that has a some classes using functions defined in some C files in the same directory. If inside the C++ source file I use: extern "C"{ // C function declarations } //C++ code
10
6200
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: // main.cpp // This is defined in a C module extern "C" void fake_qsort(void*, std::size_t, std::size_t, int (*compare)(const void*, const void*));
12
2730
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external linkage? Not much on this in the FAQ or tutorials.
19
3861
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default storage-class specifier. My (little) C experience tells me that an object with "extern" is to let the linker knows that the object is referencing the object defined in somewhere, and this "somewhere" object does not have the storage-class specifier...
5
1937
by: jchludzinski | last post by:
I have 3 files (see below: a.h, w.c, ww.c). I would like to use a single x (declared somewhere) which would global to both compilation units: w.c & ww.c. No matter where I place the "extern" qualifier - it appears to work: x is shared between w.c and ww.c. Or if I simple don't use "extern", it works. Why? What is the correct (or simply preferred) usage? ---John PSI'm using gcc (GCC) 4.0.2.
2
1906
by: Bharath | last post by:
Hi All, I am a newbie to C++ and I'm trying to figure this out. Can you please help? We have 3rd party library that's written in c++. We don't have the source for it. ldd on that shared library indicates that it depends on libstdc++. It has a printf() like function called void xxx_print (char *format, ...)
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.