关于混合C和C ++的问题 [英] A concern about mixing C and C++

查看:65
本文介绍了关于混合C和C ++的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个问题,我正在寻求一些建议。


我正在努力实现一个算法库。因为

性能是后来应用程序中最重要的因素,所以
决定用C而不是C ++编写它。但是,我认为在某些misc地方使用某些C ++代码可能会很方便

。我知道,我可以随时使用C ++编译器来使它工作。


我关注的是:

1)我混合C和C ++代码的方式是否有任何潜在的缺点?

性能?

2)我将C和C ++混合使用的方式代码有未来用户使用库的任何潜在的缺点吗?


我选择C接口而不是C ++ OOD的意图是获得

尽可能提高性能,但我仍然喜欢使用一些C ++
编码功能(例如,const,引用而不是指针,......)。


谢谢,


加里

解决方案

ziman137写道:


大家好,


我有一个问题,我正在寻求一些建议。


我目前正在努力实现算法库。因为

性能是后来应用程序中最重要的因素,所以
决定用C而不是C ++编写它。



为什么? C ++版本的性能应该不比C one

差,如果你能利用现有的经过良好调整的标准算法和容器,可能会更好。你的分析显示了什么?


但是,我认为在某些misc地方使用某些C ++代码可能会很方便。我知道,我/ b $ b总是可以使用C ++编译器来使它工作。



你可以,是的。


我的担忧是:


1)我混合C和C ++代码的方式是否有任何潜在的弊端

表现?



无所不知。


2)我混合C和C ++代码的方式是否有任何意义

未来用户使用库的潜在缺点?



是的,除非您发布源代码,否则如果您公开任何C ++接口

将遇到困扰C ++

库的所有ABI不兼容问题。您还将排除C用户使用您的库。一个

妥协只是暴露一个C接口。


我选择C接口而不是C ++ OOD的意图是获得

尽可能提高性能,但我仍然喜欢使用一些C ++
编码功能(例如,const,引用而不是指针,......)。



性能与它无关,便携性是坚持使用C接口的原因。

-

Ian Collins。


2006年7月28日22:28:52 -0700," ziman137" < ga ******** @ yahoo.comwrote
comp.lang.c中的


Hello all,


我有一个问题,我正在寻求一些建议。



这里的建议:不要问这里。就C来说,C ++只是

很多很多johnny来自最近的模仿者之一,声称要改进

并扩展C.


C标准没有定义任何其他语言的接口。根本不是
。另一方面,C ++定义了一种机制,用于允许混合来自兼容的C

编译器的代码。

(但不能保证)。


我目前正在努力实现一个算法库。因为

性能是后来应用程序中最重要的因素,所以
决定用C而不是C ++编写它。但是,我认为在某些misc地方使用某些C ++代码可能会很方便

。我知道,我/ b $ b总是可以使用C ++编译器来实现它。



绝对令人惊讶。有什么证据证明C会比C ++提供更好的性能?b $ b?您运行了哪些试验,以及时间比较结果在哪里?


我的担忧是:


1)我混合C和C ++代码的方式是否有任何潜在的弊端?

性能如何?



C没有定义任何混合C和C ++的方法。


2)我会这样吗mix C和C ++代码有什么潜在的弊端

未来用户使用该库?



C没有定义任何混合C和C ++的方法。


我选择C接口的意图而不是C ++ OOD是为了获得尽可能最大的性能,但我仍然喜欢使用一些C ++

编码功能(例如,const,而不是参考指针,...)。



但你有什么证据表明这个选择会对

的表现产生什么影响?


至于混合C ++编码特征,例如参考等。使用C代码,

这简直是不可能的,因为在C中没有诸如
引用的东西。


以下是一些提示:


如果你想了解混合C ++和C,请在C ++新闻组中询问。


如果你想要要了解混合Java和C,请在Java小组中询问。


如果你想了解...


... .well,你现在可能已经明白了这一点。


C远远高于当月流行的许多语言,

和没有注意到他们的存在。它很可能比其中的许多或全部更长久,因为它已经超过了原始的

Visual Basic for Windows。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

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




" ziman137" < ga ******** @ yahoo.com写了留言


大家好,


我有一个问题,我正在寻求一些建议。


我目前正在努力实现一个算法库。因为

性能是后来应用程序中最重要的因素,所以
决定用C而不是C ++编写它。但是,我认为在某些misc地方使用某些C ++代码可能会很方便

。我知道,我/ b $ b总是可以使用C ++编译器来实现它。


1)我将混合使用C和C ++代码

表现有任何潜在的弊端吗?



可能是的。它必须使用C ++编译器进行编译,而且给定系统上的C ++编译器不如C / /
编译器,这不是不可能的。但是它不太可能,通常它们分享相同的代码。

如果你在代码中使用C ++构造,你会发现它们更难以优化
$ C $ b比C构造,因为C ++旨在向程序员提供一个很好的接口,而不是暴露基本的处理器操作。然而

你可能已经意识到了这一点。

-
www.personal.leeds.ac.uk/~bgy1mm

免费下载游戏。


Hello all,

I have a question and am seeking for some advice.

I am currently working to implement an algorithmic library. Because
the performance is the most important factor in later applications, I
decide to write it in C instead of C++. However, I thought it might be
convenient to use some C++ code at some misc places. I''m aware that, I
could always use the C++ compiler to get it work.

My concerns are:

1) Would the way I mix C and C++ code have any potential drawbacks to
the performance?
2) Would the way I mix C and C++ code have any potential drawbacks for
the future users to use the library?

My intention for choosing C interface instead of C++ OOD is to gain the
maximum performance as possible, yet I still like to use some C++
coding features (e.g., "const", reference instead of pointers, ...).

Thanks,

Gary

解决方案

ziman137 wrote:

Hello all,

I have a question and am seeking for some advice.

I am currently working to implement an algorithmic library. Because
the performance is the most important factor in later applications, I
decide to write it in C instead of C++.

Why? The performance of a C++ version should be no worse than the C one
and possibly better if you can make use of existing well tuned standard
algorithms and containers. What did your profiling show?

However, I thought it might be
convenient to use some C++ code at some misc places. I''m aware that, I
could always use the C++ compiler to get it work.

You could, yes.

My concerns are:

1) Would the way I mix C and C++ code have any potential drawbacks to
the performance?

None what so ever.

2) Would the way I mix C and C++ code have any potential drawbacks for
the future users to use the library?

Yes, unless you release the source, if you expose any C++ interfaces you
will run into all of the ABI incompatibility problems that plague C++
libraries. You will also exclude C users from using you library. One
compromise is to only expose a C interface.

My intention for choosing C interface instead of C++ OOD is to gain the
maximum performance as possible, yet I still like to use some C++
coding features (e.g., "const", reference instead of pointers, ...).

Performance has nothing to do with it, portability is the reason to
stick with a C interface.

--
Ian Collins.


On 28 Jul 2006 22:28:52 -0700, "ziman137" <ga********@yahoo.comwrote
in comp.lang.c:

Hello all,

I have a question and am seeking for some advice.

Here''s advice: don''t ask here. As far as C is concerned, C++ is just
one of many, many johnny-come-lately imitators that claim to improve
and extend C.

The C standard does not define an interface to any other language. Not
at all. C++, on the other hand, defines a mechanism that is intended
(but not guaranteed) to allow mixing code from a compatible C
compiler.

I am currently working to implement an algorithmic library. Because
the performance is the most important factor in later applications, I
decide to write it in C instead of C++. However, I thought it might be
convenient to use some C++ code at some misc places. I''m aware that, I
could always use the C++ compiler to get it work.

Absolutely astonishing. What proof do you have that C will provide
better performance than C++? What trials have you run, and where are
the timing comparison results?

My concerns are:

1) Would the way I mix C and C++ code have any potential drawbacks to
the performance?

C does not define any way to mix C and C++.

2) Would the way I mix C and C++ code have any potential drawbacks for
the future users to use the library?

C does not define any way to mix C and C++.

My intention for choosing C interface instead of C++ OOD is to gain the
maximum performance as possible, yet I still like to use some C++
coding features (e.g., "const", reference instead of pointers, ...).

But what evidence do you have that this choice will have any impact on
performance?

As for mixing C++ coding features such as "references" with C code,
that''s just plain impossible, since there are no such things as
references in C.

Here are some hints:

If you want to know about mixing C++ and C, ask in a C++ newsgroup.

If you want to know about mixing Java and C, ask in a Java group.

If you want to know about...

....well, you''re probably getting the point by now.

C is far senior to many of the popular flavor of the month languages,
and does not take any notice of their existence. And it may well
outlast many or all of them, as it has outlasted at least the original
Visual Basic for Windows.

--
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



"ziman137" <ga********@yahoo.comwrote in message

Hello all,

I have a question and am seeking for some advice.

I am currently working to implement an algorithmic library. Because
the performance is the most important factor in later applications, I
decide to write it in C instead of C++. However, I thought it might be
convenient to use some C++ code at some misc places. I''m aware that, I
could always use the C++ compiler to get it work.

1) Would the way I mix C and C++ code have any potential drawbacks to
the performance?

Potentially yes. It must be compiled with a C++ compiler, and it is not
impossible that the C++ compiler on a given system is inferior to the C
compiler. However it is not very likely, often they share substantially the
same code.
If you use C++ constructs in your code you will find them harder to optimise
than the C constructs, because C++ is designed to present a nice interface
to the programmer rather than to expose basic processor operations. However
you are probably aware of that already.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.


这篇关于关于混合C和C ++的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆