使用CPP编译器编译C代码? [英] Compile C Code With A CPP Compiler?
问题描述
嘿所有,
我正在使用一些遗留的C代码,我想把它编译为
a CPP文件。
我收到以下错误消息:
driver.cpp:87:无法在
分配
通过网络阅读我在C和C之间发现了一些模糊的引用
''无效''问题C ++,我不太了解C ++,并且会赞赏任何可能帮助我的指针或参考文件。
谢谢!
entropy
Hey all,
I''m working with some legacy C code and I would like to compile it as
a CPP file.
I get the following error message:
driver.cpp:87: cannot convert `void *'' to `GenericStruct *'' in
assignment
Reading through the web I''ve come across vague references to the
''void'' issue between C and C++, I don''t know C++ well and would
appreciate any pointers or references which might help me out.
Thanks!
entropy
推荐答案
em ************** @ yahoo.com (entropy123)写在
新闻:90 **** **********************@posting.google.c om:
em**************@yahoo.com (entropy123) wrote in
news:90**************************@posting.google.c om:
我正在处理一些遗产C代码,我想把它编译成一个CPP文件。
到底是什么?
我收到以下错误信息:
driver.cpp:87:无法转换`void *
赋值中的'GenericStruct *''
我相信C ++需要对void指针进行显式强制转换,你可能会在C ++中问这个
。
通过网络阅读我偶然发现了C和C ++之间的无效问题,我不太了解C ++并且不会感谢任何可能帮助我的指针或参考资料。
I''m working with some legacy C code and I would like to compile it as
a CPP file.
To what end?
I get the following error message:
driver.cpp:87: cannot convert `void *'' to `GenericStruct *'' in
assignment
I believe C++ requires explicit casts on void pointers, you might ask this
in C++.
Reading through the web I''ve come across vague references to the
''void'' issue between C and C++, I don''t know C++ well and would
appreciate any pointers or references which might help me out.
两种方法:(1)在找到C ++适当的方法之后
将void指针转换为其他类型,使用
强制转换修复所有此类转换,(2)偏离主题但您可能会发现存在编译器覆盖
切换强制C ++编译器将.cpp文件作为.c文件。
后者的好处是允许你使用一个编译器
你的C和C ++源码不会允许你将C ++功能添加到
文件中。
我不知道编译真正的C文件有什么好处带有
C ++编译器的.cpp文件会给你。奇怪的是,我必须在我的
当前项目中这样做,因为它曾经被认为我们将驱动程序转换为C ++。
因此,我告诉了我们的编译器(Diab)将我的.cpp文件视为.c文件。
我还用以下内容包装了整个文件的内容:
#ifdef __cplusplus
externC {
#endif
/ *文件* /
#ifdef __cplusplus
}
#endif
-
- 马克 - >
-
Two approaches: (1) after finding out the C++ appropriate method of
converting void pointers to other types, fix-up all such conversions with
casts, (2) off-topic but you might find that there is a compiler override
switch to force the C++ compiler to theat a .cpp file as a .c file.
The latter has the benefit of allowing you to use one compiler for both
your C and C++ sources but won''t allow you to add C++ features to said
files.
I''m not sure what benefit compiling a true C file as a .cpp file with a
C++ compiler will give you. Oddly enough, I have had to do that on my
current procject because it was once thought we''d convert drivers to C++.
Hence, I have told our compiler (Diab) to treat my .cpp files as .c files.
I''ve also wrapped the contents of the entire file with:
#ifdef __cplusplus
extern "C" {
#endif
/* File */
#ifdef __cplusplus
}
#endif
--
- Mark ->
--
" entropy123" < EM ************** @ yahoo.com>在留言中写道
news:90 ************************** @ posting.google.c om ...
"entropy123" <em**************@yahoo.com> wrote in message
news:90**************************@posting.google.c om...
嘿所有,
我正在使用一些遗留的C代码,我想把它编译为一个CPP文件。
我收到以下错误信息:
driver.cpp:87:
赋值中无法将`void *''转换为'GenericStruct *'' >
通过网络阅读我遇到了对C和C ++之间的无效问题的模糊提及,我不太了解C ++并且会赞赏任何指针或引用可能会帮助我。
Hey all,
I''m working with some legacy C code and I would like to compile it as
a CPP file.
I get the following error message:
driver.cpp:87: cannot convert `void *'' to `GenericStruct *'' in
assignment
Reading through the web I''ve come across vague references to the
''void'' issue between C and C++, I don''t know C++ well and would
appreciate any pointers or references which might help me out.
您的c ++相关问题最好在c ++特定的
新闻组之一中得到解答,例如comp.lang.c ++。
[OT]没有看到实际的代码,我最好的猜测是你需要
转换为void类型的表达式*键入GenericStruct *,因为在C ++下不存在从void *到GenericStruct *的隐式
转换。 [/ OT]
Your c++ related question is best answered in one of the c++ specific
newsgroups, e.g. comp.lang.c++.
[OT] Without seeing the actual code, my best guess would be that you need to
cast the expression of type void* to type GenericStruct*, as no implicit
conversion from void* to GenericStruct* exists under C++. [/OT]
" entropy123" < EM ************** @ yahoo.com>在留言中写道
news:90 ************************** @ posting.google.c om ...
"entropy123" <em**************@yahoo.com> wrote in message
news:90**************************@posting.google.c om...
嘿所有,
我正在使用一些遗留的C代码,我想把它编译为一个CPP文件。
''CPP文件''不是由<br />
C或C ++语言定义的概念。你是说你想要
翻译一个最初用C语言编写的文件,用
一个C ++编译器?这让我问,为什么?
注意一些C构造
在C ++中无效,反之亦然。
>
另请注意,C ++在这里不是主题。
我收到以下错误消息:
driver.cpp:87:无法转换`void *''
赋值中的'GenericStruct *''
这是C ++程序的有效诊断,但对于C程序不是
。
通过网络阅读我遇到了对C和C ++之间的问题的模糊引用,
你不能通过网上冲浪学习语言或差异,
。你需要书籍。
我不知道C ++好吗
书籍! :-)
并且会赞赏任何可能帮助我的指针或参考文献。
Hey all,
I''m working with some legacy C code and I would like to compile it as
a CPP file.
''CPP file'' is not a concept defined by either the
C or C++ languages. Did you mean you wanted to
translate a file originally written in C with
a C++ compiler? This causes me to ask, why?
Note that some C constructs
are not valid in C++, and vice versa.
Also note that C++ is not topical here.
I get the following error message:
driver.cpp:87: cannot convert `void *'' to `GenericStruct *'' in
assignment
This is a valid diagnostic for a C++ program, but not
for a C program.
Reading through the web I''ve come across vague references to the
''void'' issue between C and C++,
You cannot learn either language, or the differences,
by surfing the web. You need books.
I don''t know C++ well
Books! :-)
and would
appreciate any pointers or references which might help me out.
我指向并推荐你C ++书籍:
http:// www .accu.org / bookreviews / publ ... nner_s_c __。htm
并解决您的直接问题:
C允许将''void *'转换为任何
其他指针类型而不使用强制转换。 C ++需要
一个演员。 (我猜这是发生'
调用''malloc()'')
#include< stdlib.h>
int main()
{
struct GenericStruct
{
/ *无论* /
} the_data;
GenericStruct * gsp =(GenericStruct *)malloc(sizeof the_data);
/ *无论* /
免费((void *)gsp);
返回0;
}
>
关于此的进一步讨论属于C ++组,
或''alt.comp.lang.learn.c-c ++''组,其中两者都是
langs是热门话题。
后续设置。
-Mike
I point and refer you to C++ books:
http://www.accu.org/bookreviews/publ...nner_s_c__.htm
and address your immediate problem:
C allows the conversion of ''void*'' to and from any
other pointer type without a cast. C++ requires
a cast. (I''m guessing this is happening with an
invocation of ''malloc()'')
#include <stdlib.h>
int main()
{
struct GenericStruct
{
/* whatever */
} the_data;
GenericStruct* gsp = (GenericStruct*)malloc(sizeof the_data);
/* whatever */
free((void*)gsp);
return 0;
}
Further discussions about this belong in a C++ group,
or the ''alt.comp.lang.learn.c-c++'' group, where both
langs are topical.
Followups set.
-Mike
这篇关于使用CPP编译器编译C代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!