473,799 Members | 3,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it a good thing that program mix C and C++?

Is it a good thing that program mix C and C++?

Mar 28 '07
45 2075
Richard Heathfield wrote:
Ian Collins said:
>>Richard Heathfield wrote:
>>>Ian Collins said:

CBFalcone r wrote:

>dolphin wrote:
>
>>Is it a good thing that program mix C and C++?
>
>Mix, no. You can call C routines from C++, but not the reverse.

No so, C++ provides a mechanism (the extern "C" linkage specifier) to
make C++ functions callable from C.

No, it doesn't. It makes C functions callable from C++.

All together now: oh yes it does!

I can find no evidence in ISO/IEC 9899 to support your claim - or, for
that matter, my own claim that it makes C functions callable from C++.
I therefore withdraw that claim. Please provide chapter and verse from
ISO/IEC 9899 for extern "C" being a mechanism to C++ functions callable
from C, or alternatively follow my lead by withdrawing your claim.
That's almost as daft as asking me to show where ISO/IEC 9899 states
that the sky is blue.

--
Ian Collins.
Mar 28 '07 #21
On Mar 28, 10:30 am, SM Ryan <wyrm...@tang o-sierra-oscar-foxtrot-
tango.fake.orgw rote:
CBFalconer <cbfalco...@yah oo.comwrote:
# Ian Collins wrote:
# CBFalconer wrote:
# >dolphin wrote:

# >>
# >>Is it a good thing that program mix C and C++?
# >>
# >Mix, no. You can call C routines from C++, but not the reverse.
# >
# No so, C++ provides a mechanism (the extern "C" linkage specifier)
# to make C++ functions callable from C.
#
# That makes C callable from C++. Not the reverse.

That comes as a real shock to those of us who do so, by deviously
following the extern "C" rules explicitly intended to allow this.
Albeit at great danger in either case.

For instance, you cannot mix try/catch with setjmp()/longjmp().
Are you absolutely certain that setjmp()/longjmp() are not used
anywere in the C routines (including library calls)?
How about try/catch?

There are other dangers as well.

Mar 28 '07 #22
Ian Collins said:
Richard Heathfield wrote:
<snip>
>Please provide chapter and
verse from ISO/IEC 9899 for extern "C" being a mechanism to [make]
C++ functions callable from C, or alternatively follow my lead by
withdrawing your claim.
That's almost as daft as asking me to show where ISO/IEC 9899 states
that the sky is blue.
And indeed, as I look out of my window, I see that the sky is not blue.
It's quite a deep black, actually.

Had ISO/IEC 9899 guaranteed the blueness of the sky, I would have had
cause for complaint about non-conformance. As it doesn't offer any such
guarantee, however, I fail to see the relevance of your objection.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 28 '07 #23
Richard Heathfield wrote:
Ian Collins said:

>>Richard Heathfield wrote:


<snip>
>>>Please provide chapter and
verse from ISO/IEC 9899 for extern "C" being a mechanism to [make]
C++ functions callable from C, or alternatively follow my lead by
withdrawin g your claim.

That's almost as daft as asking me to show where ISO/IEC 9899 states
that the sky is blue.


And indeed, as I look out of my window, I see that the sky is not blue.
It's quite a deep black, actually.

Had ISO/IEC 9899 guaranteed the blueness of the sky, I would have had
cause for complaint about non-conformance. As it doesn't offer any such
guarantee, however, I fail to see the relevance of your objection.
There is a world beyond ISO/IEC 9899, so just as ISO/IEC 9899 doesn't
guarantee the blueness of the sky, it doesn't say anything regarding how
other languages make their functions callable from C.

--
Ian Collins.
Mar 28 '07 #24
Ian Collins said:
There is a world beyond ISO/IEC 9899
Chapter and verse, please. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 28 '07 #25
Richard Heathfield wrote:
Ian Collins said:

>>There is a world beyond ISO/IEC 9899


Chapter and verse, please. :-)
We are still waiting for the first draft of the ISO "Life, the Universe
and Everything" specification. I'll get back to you when it is released....

--
Ian Collins.
Mar 28 '07 #26
In article <57************ *@mid.individua l.net>,
Ian Collins <ia******@hotma il.comwrote:
>>>There is a world beyond ISO/IEC 9899
>Chapter and verse, please. :-)
>We are still waiting for the first draft of the ISO "Life, the Universe
and Everything" specification. I'll get back to you when it is released....
There was a W3C specification for this, but it never got past the
Candidate Recommendation stage because of the lack of two compatible
implementations .

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 28 '07 #27
Richard Heathfield <rj*@see.sig.in validwrites:
Ian Collins said:
>Richard Heathfield wrote:
>>Ian Collins said:
CBFalcone r wrote:
[...]
>>>>>Mix, no. You can call C routines from C++, but not the reverse.

No so, C++ provides a mechanism (the extern "C" linkage specifier) to
make C++ functions callable from C.

No, it doesn't. It makes C functions callable from C++.
All together now: oh yes it does!

I can find no evidence in ISO/IEC 9899 to support your claim - or, for
that matter, my own claim that it makes C functions callable from C++.
I therefore withdraw that claim. Please provide chapter and verse from
ISO/IEC 9899 for extern "C" being a mechanism to C++ functions callable
from C, or alternatively follow my lead by withdrawing your claim.
The lack of any mention of this in ISO/IEC 9899 indicates that the
claim is off-topic. It does not indicate that it should be withdrawn,
<OT>particularl y since the claim happens to be correct</OT>.
Withdrawing a claim tends to imply that it's untrue, not merely that
it should not have been made.

If your call to withdraw the claim was not intended to imply that the
claim is untrue, then I have no argument (except for your potentially
misleading choice of words).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 28 '07 #28
Ian Collins wrote:
CBFalconer wrote:
>Ian Collins wrote:
>>CBFalconer wrote:
dolphin wrote:

Is it a good thing that program mix C and C++?

Mix, no. You can call C routines from C++, but not the reverse.

No so, C++ provides a mechanism (the extern "C" linkage specifier)
to make C++ functions callable from C.

That makes C callable from C++. Not the reverse.

It's a two way street.
No it isn't. The C++ compiler does various unspeakable things to
the function names in order to handle overloading, i.e. it creates
multiple names for functions depending on the types of their
parameters. It calls these functions with similarly adorned
names. This is all necessary to make C++ work. A C header file
can conditionally (on __cplusplus) include the extern "C" { .... }
wrapper on the function prototypes, which tells the C++ compiler
that these calls are unadorned. Now the linker can work.

Since the C++ object code uses those adorned names, the C compiler
has no way of generating calls to them. If you try to compile the
C code with a C++ compiler you have other problems, because they
are different languages.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 29 '07 #29
CBFalconer wrote:
Ian Collins wrote:
>>CBFalconer wrote:
>>>Ian Collins wrote:

CBFalcone r wrote:

>dolphin wrote:
>
>
>>Is it a good thing that program mix C and C++?
>
>Mix, no. You can call C routines from C++, but not the reverse.

No so, C++ provides a mechanism (the extern "C" linkage specifier)
to make C++ functions callable from C.

That makes C callable from C++. Not the reverse.

It's a two way street.


No it isn't. The C++ compiler does various unspeakable things to
the function names in order to handle overloading, i.e. it creates
multiple names for functions depending on the types of their
parameters. It calls these functions with similarly adorned
names. This is all necessary to make C++ work. A C header file
can conditionally (on __cplusplus) include the extern "C" { .... }
wrapper on the function prototypes, which tells the C++ compiler
that these calls are unadorned. Now the linker can work.
extern "C" linkage suppresses name mangling for functions compiled as
C++. The rules of C++ permit only one instance of any extern "C"
function name, they can not be overloaded and they can be called from C.
Since the C++ object code uses those adorned names, the C compiler
has no way of generating calls to them.
It dose if they are declared extern "C" because the functions are not
mangled.

--
Ian Collins.
Mar 29 '07 #30

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

Similar topics

24
3617
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works, first and foremost. If it works well, even better. The same goes for ease of maintenance, memory footprint, speed, etc, etc. Most of the time, people are writing code for a use in the *real world*, and not just as an academic exercise. Look at...
36
4657
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am proposing a single column table with a field name called vehicle_type and this will contain the vehicle type. Sot it will be
39
2864
by: Suresh | last post by:
Hi, I am new to C and curious to know some basic questions about C. Why C is good? In what way its better than any other languages? If it is no longer a choice of programming language...why people still study it? And also its not an OO language either...is there any advantages in being not an OO language? I know one reason is that, IT started with C and so they are still using
113
12359
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
13
2105
by: KV | last post by:
I'm new to OO Design, and I'm fixing to start writing my very first C# program. Given the complexity of OO programming, I would like to run something by this group and get general input. My example is a program called HijackThis. I'm sure many are familiar that it is a spyware removal tool. The program looks at over 20 places on Windows computers to see what is starting (with options to remove the offending software). The program can...
11
3810
by: Someonekicked | last post by:
I want to save tables of integers to files. One way to write the cells as fixed size in the file, is to use reinterpret_cast. Is that a bad choice, good choice? I remember once before I posted a program using it, and some suggested that I might get errors using it. are there any other ways to write the cells as fixed size in the file? (knowing the cells will only contain integers). here is how I plan to do it (without much caring...
63
3983
by: John Salerno | last post by:
I know there's a request for a good IDE at least once a week on the ng, but hopefully this question is a little different. I'm looking for suggestions for a good cross-platform text editor (which the features for coding, such as syntax highlighting, etc.) but not a full IDE with all the fancy jazz (GUI developer, UML diagrams, etc.). Ideally, it would be something I could even put on a flash drive and move from computer to computer, but...
6
1874
by: mast2as | last post by:
I have posted a few messages in the last few days about a project I am working on which is a quite simple parser. I ended up using the try/ catch structure as a general mechanism to control what's happening in the program when it finds a syntax error in the file it parses. I would like to know if this is 'an acceptable thing to do' from a programmation point of view, or if I should keep using it only for catch exception created withing the...
0
9685
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
9538
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
10470
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...
1
10214
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
7561
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
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
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.