C99 / C89 [英] c99/c89

查看:72
本文介绍了C99 / C89的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下程序有什么问题。


int * myMalloc(int Size)

{

int a [大小];

返回一个;

}


我们可以使用sizeof运算符来查找sizeof数组''a'';


谢谢

shaan。

what is the problem with following programme.

int * myMalloc(int Size)
{
int a[Size];
return a;
}

can we use sizeof operator to find sizeof array ''a'';

Thanks
shaan.

推荐答案

shaanxxx写道:
shaanxxx wrote:

>

以下程序有什么问题。


int * myMalloc (int尺寸)

{

int a [尺寸];

返回a;

}


我们可以使用sizeof运算符来查找sizeof数组''a'';
>
what is the problem with following programme.

int * myMalloc(int Size)
{
int a[Size];
return a;
}

can we use sizeof operator to find sizeof array ''a'';



您将返回不再存在的东西。


-

Chuck F( cb********@yahoo.com)(cb********@maineline.net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.netUSE maineline地址!

You are returning something that no longer exists.

--
Chuck F (cb********@yahoo.com) (cb********@maineline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.netUSE maineline address!


shaanxxx写道:
shaanxxx wrote:

以下程序有什么问题。


int * myMalloc(int Size)

{

int a [大小];

返回一个;

}


我们可以使用sizeof运算符来查找sizeof数组''a'' ;
what is the problem with following programme.

int * myMalloc(int Size)
{
int a[Size];
return a;
}

can we use sizeof operator to find sizeof array ''a'';



在c99中,是的。


但是你返回一个指向

的指针函数完成时不存在。不要这样做。

In c99, yes.

You are however returning a pointer to something that
doesn''t exist when the function finishes. Don''t do that.


CBFalconer写道:
CBFalconer wrote:

shaanxxx写道:
shaanxxx wrote:

>>
以下程序有什么问题。

int * myMalloc(int Size)
{
int a [Size];
返回一个;
}

我们可以使用sizeof运算符来查找sizeof数组''a'';
>>
what is the problem with following programme.

int * myMalloc(int Size)
{
int a[Size];
return a;
}

can we use sizeof operator to find sizeof array ''a'';



您将返回不再存在的内容。


You are returning something that no longer exists.



Nit:他们正在返回/指针/不再存在的东西。


注意:这假设C99(或可变长度

数组的假朋友)。


-

Chris" nut" Dollin

永远不要问这个问题! Kosh大使/巴比伦5 /

Nit: they''re returning a /pointer/ to something that no longer exists.

Note: this assumes C99 (or a false friend with variable-length
arrays).

--
Chris "nut" Dollin
"Never ask that question!" Ambassador Kosh, /Babylon 5/


这篇关于C99 / C89的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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