使用c ++编译malloc [英] compilation of malloc using c++
问题描述
大家好,
我需要使用c ++编译器编译c代码。在c代码中我使用malloc和free来支持
。
1)我怀疑使用c ++编译器编译malloc是否可以?
2)行为是否未定义?
问候,
Somenath
Hi All,
I need to compile c code using c++ compiler .Inside the c code I am
using malloc and free.
1) My doubt is it ok to compile malloc using c++ compiler?
2)Is behavior will be undefined ?
Regards,
Somenath
推荐答案
somenath< so ********* @ gmail.comwrote :
somenath <so*********@gmail.comwrote:
我需要使用c ++编译器编译c代码。在c代码中我使用malloc和free来使用
。
I need to compile c code using c++ compiler .Inside the c code I am
using malloc and free.
1)我怀疑使用c ++编译器编译malloc是否可以?
1) My doubt is it ok to compile malloc using c++ compiler?
malloc()和free()是函数,所以你不编译它们,
你的程序只是调用它们。但是由于C ++不是C,你必须将
转换为malloc()的返回值,将指定返回值的
指针的类型转换为 - in与C相比,
这通常不是一个好主意。
问候,Jens
-
\ Jens Thoms Toerring ___ jt@toerring.de
\ __________________________ http://toerring.de
somenath写道:
somenath wrote:
>
大家好,
我需要使用c ++编译器编译c代码.Inside c代码我是使用malloc和free的
。
1)我怀疑使用c ++编译器编译malloc是否可以?
2)行为是不确定的?
>
Hi All,
I need to compile c code using c++ compiler .Inside the c code I am
using malloc and free.
1) My doubt is it ok to compile malloc using c++ compiler?
2)Is behavior will be undefined ?
你需要在comp.lang.c ++中询问,在大厅和左边。
-
+ ------------------------- + --------------- ----- + ----------------------- +
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |
+ ------------------------- + --------- ----------- + ----------------------- +
不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>
You would need to ask in comp.lang.c++, down the hall and to the left.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>
文章< 11********************@d30g2000prg.googlegroups.c om>,
somenath< so ******** *@gmail.com写道:
In article <11********************@d30g2000prg.googlegroups.c om>,
somenath <so*********@gmail.comwrote:
>大家好,
我需要使用c ++编译器编译c代码。
>Hi All,
I need to compile c code using c++ compiler .
你真的想做什么?使用
a编译器编译另一种语言的代码总是一个坏主意。
What are you Really Trying To Do? Compiling code in one language with
a compiler for another language is Always A Bad Idea.
在c代码中我是
使用malloc和free。
1)我怀疑使用c ++编译器编译malloc是否可以?
Inside the c code I am
using malloc and free.
1) My doubt is it ok to compile malloc using c++ compiler?
为什么要问comp.lang.c关于C ++?
正确答案是不要做那。如果你想使用C ++,调用
malloc几乎总是分配内存的错误方法。使用new或
new []代替;这就是它的用途。
Why are you asking comp.lang.c about C++?
The right answer is to Don''t Do That. If you want to use C++, calling
malloc is almost always the wrong way to allocate memory. Use new or
new[] instead; that''s what it''s there for.
> 2)行为是否未定义?
>2)Is behavior will be undefined ?
我相信malloc的行为在C ++中非常明确。
dave
-
Dave Vandervies dj ****** @ csclub.uwaterloo.ca
当其他孩子害怕怪物时,你的孩子可能会拿出一支
棒球棒而且如果有一个怪物,那么就会感到很失望。床...
- 在可怕的魔鬼修道院里的Juergen Nieveler
I believe malloc''s behavior is perfectly well-defined in C++.
dave
--
Dave Vandervies dj******@csclub.uwaterloo.ca
When other kids are scared of monsters, your kid might turn out to grab a
baseball bat and be disappointed if there WASN''T a monster under the bed...
--Juergen Nieveler in the scary devil monastery
这篇关于使用c ++编译malloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!