473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

iso c++ standard on c linkage

I'm given to understand that your standard is specific regarding linking to
c. Furthermore I'm going to speculate that there exists a c++ version of
Keith Thompson, brilliant, encyclopedic and able to confuse by giving me the
exact answer, all 42 volumes. I just want to know wrap a C function so that
I don't stomp all over it when I bring it down the hall. cheers, furunculus
-------------------------
Das ist dies, therefore that is 'this'.
Jun 24 '06 #1
5 1309
On Sat, 24 Jun 2006 12:54:48 -0400, "Your Uncle"
<in*****@crippled.net> wrote in comp.lang.c++:
I'm given to understand that your standard is specific regarding linking to
c. Furthermore I'm going to speculate that there exists a c++ version of
Keith Thompson, brilliant, encyclopedic and able to confuse by giving me the
exact answer, all 42 volumes. I just want to know wrap a C function so that
I don't stomp all over it when I bring it down the hall. cheers, furunculus


The C++ language allows linkage specifications, of which it
specifically defines exactly one, extern "C". The intent is that such
functions should be compiled in such a way that they may be linked
with code compiled with a compatible C compiler, or perhaps call
system functions designed to be called from C. Note that the standard
neither requires nor guarantees that extern "C" will provide
compatibility with any particular C compiler or system call.

What extern "C" specifically does not do is make the C++ compiler
compile C code. The code is still treated by the compiler as C++
code. Only the linkage is changed.

That means that you can't compile C code with a C++ compiler and
extern "C" if it contains any of the many imcompatibilities between C
and C++.

This function cannot be compiler by a C++ compiler, regardless of
whether you try to give it C linkage:

void func()
{
int new; // reserved word used as variable name
double static_cast; // ditto
void *vp = 0;
int *ip = vp; // can't assign void* to object *
}

If you want to write code that can compile as C and also as C++ with C
linkage, you must restrict yourself to the common subset of C and C++.
In at least some cases, this results in code that is neither good C
nor good C++.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jun 24 '06 #2

"Jack Klein" <ja*******@spamcop.net> wrote in message
news:le********************************@4ax.com...
On Sat, 24 Jun 2006 12:54:48 -0400, "Your Uncle"
<in*****@crippled.net> wrote in comp.lang.c++:
I'm given to understand that your standard is specific regarding linking
to
c. Furthermore I'm going to speculate that there exists a c++ version of
Keith Thompson, brilliant, encyclopedic and able to confuse by giving me
the
exact answer, all 42 volumes. I just want to know wrap a C function so
that
I don't stomp all over it when I bring it down the hall. cheers,
furunculus
The C++ language allows linkage specifications, of which it
specifically defines exactly one, extern "C". The intent is that such
functions should be compiled in such a way that they may be linked
with code compiled with a compatible C compiler, or perhaps call
system functions designed to be called from C. Note that the standard
neither requires nor guarantees that extern "C" will provide
compatibility with any particular C compiler or system call.

So a commodore 64 with Vectron's compiler is not required to have it. I
believe that if extern "C" is going to work somewhere, then it would be on
my popular OS and implementation.
What extern "C" specifically does not do is make the C++ compiler
compile C code. The code is still treated by the compiler as C++
code. Only the linkage is changed.

That means that you can't compile C code with a C++ compiler and
extern "C" if it contains any of the many imcompatibilities between C
and C++.

This function cannot be compiler by a C++ compiler, regardless of
whether you try to give it C linkage:

void func()
{
int new; // reserved word used as variable name
double static_cast; // ditto
void *vp = 0;
int *ip = vp; // can't assign void* to object *
}

If you want to write code that can compile as C and also as C++ with C
linkage, you must restrict yourself to the common subset of C and C++.
In at least some cases, this results in code that is neither good C
nor good C++.

Rats. Elsewhere it was suggested that I compile the C part and the c++ part
separately and then link them as c++. Is that a pipe dream? cheers, f
Jun 24 '06 #3
Your Uncle wrote:

Rats. Elsewhere it was suggested that I compile the C part and the c++ part
separately and then link them as c++. Is that a pipe dream? cheers, f

Compile the C part as C and the C++ part as C++. Link with the C++
compiler.

If any functions in the C++ part have to be called from C, make them
extern "C".

Clear?

--
Ian Collins.
Jun 24 '06 #4

"Ian Collins" <ia******@hotmail.com> wrote in message
news:4g*************@individual.net...
Your Uncle wrote:

Rats. Elsewhere it was suggested that I compile the C part and the c++
part
separately and then link them as c++. Is that a pipe dream? cheers, f

Compile the C part as C and the C++ part as C++. Link with the C++
compiler.

If any functions in the C++ part have to be called from C, make them
extern "C".

Clear?

Alles klar. Now I've got to fiddle with my implementation. They don't
really include this part in K&R. ciao, f
Jun 24 '06 #5
Your Uncle wrote:
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4g*************@individual.net...
Your Uncle wrote:
Rats. Elsewhere it was suggested that I compile the C part and the c++
part
separately and then link them as c++. Is that a pipe dream? cheers, f


Compile the C part as C and the C++ part as C++. Link with the C++
compiler.

If any functions in the C++ part have to be called from C, make them
extern "C".

Clear?


Alles klar. Now I've got to fiddle with my implementation. They don't
really include this part in K&R. ciao, f

Which is hardly surprising what you consider how far K&R predates C++!

Remember, every time you link a C++ application against your system
libraries, you are doing exactly what I said above.

--
Ian Collins.
Jun 24 '06 #6

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

Similar topics

9
by: Alexander Stippler | last post by:
Hi, I have got a question concerning the overload resolution rules of C++ and enumeration types. The following little test program illustrates the situation: enum { red, green, blue }; ...
5
by: Nils Petter Vaskinn | last post by:
I'm using an enum that's declared within a function (since I only need it within that function.) I can't find anything about this in "The C++ Programming Language" by Stroustroup and I don't...
14
by: John Ratliff | last post by:
I'm trying to find out whether g++ has a bug or not. Wait, don't leave, it's a standard C++ question, I promise. This program will compile and link fine under mingw/g++ 3.4.2, but fails to link...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
16
by: Vadim Biktashev | last post by:
Hello all I would like to give a certain name to a certain global variable. Unfortunately, this name is already used in math.h for a mathematical function. Worse, I do need to use maths library...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
85
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C...
2
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.