Reg:内存分配 [英] Reg:Memory allocation

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

问题描述

int x;

static int y;

int * p;

int main(void)

{

int i;

int j = 9;

int * ptr;

char * str = " GOOGLE" ;;

static int a;

int k [];

int q [] = {1,2,3} ;

注册int reg;

volatile int vol;

.......

.. ...

....

返回0;

}


根据我的说法知识在上面的程序中声明的变量

存储如下:

GLOBAL VAR':

x,y存储在INITIALISED PART中数据段。

* p存储在STACK SEGMENT中。


LOCAL VAR':

所有变量都存储在在STACK SEGMENT。


我说错了吗?如果我错了,请更正。


干杯&此致,

Raghu。

HAPPY NEW YEAR-2008

int x;
static int y;
int *p;
int main(void)
{
int i;
int j=9;
int *ptr;
char *str = "GOOGLE";
static int a;
int k[];
int q[]={1,2,3};
register int reg;
volatile int vol;
.......
.....
....
return 0;
}

According to my knowledge the variables declared in the above program
are stored as follows:
GLOBAL VAR''s:
x,y are stored in INITIALISED PART OF DATA SEGMENT.
*p is stored in STACK SEGMENT.

LOCAL VAR''s:
all variables are stored in STACK SEGMENT.

Am I correct? Please correct if i''m wrong.

Cheers & Regards,
Raghu.
HAPPY NEW YEAR-2008

推荐答案

周六,29日2007年12月00:48:39 -0600,raghu写了

(文章

< 9d **************** ******************@l6g2000prm.g ooglegroups.com>):
On Sat, 29 Dec 2007 00:48:39 -0600, raghu wrote
(in article
<9d**********************************@l6g2000prm.g ooglegroups.com>):

int x;

static int y;

int * p;

int main(无效)

{

int i;

int j = 9;

int * ptr;

char * str =" GOOGLE";

static int a;

int k [];

int q [] = {1,2,3};

注册int reg;

volatile int vol;

......

....

...

返回0;

}


据我所知,上述程序中声明的变量

存储如下:

GLOBAL VAR':

x,y存储在INITIALISED PART OF DATA SEGMENT中。

* p存储在STACK SEGMENT中。


LOCAL VAR':

所有变量都存储在STACK SEGMENT中。


我是否正确?如果我错了,请更正。


干杯&此致,

Raghu。

HAPPY NEW YEAR-2008
int x;
static int y;
int *p;
int main(void)
{
int i;
int j=9;
int *ptr;
char *str = "GOOGLE";
static int a;
int k[];
int q[]={1,2,3};
register int reg;
volatile int vol;
......
....
...
return 0;
}

According to my knowledge the variables declared in the above program
are stored as follows:
GLOBAL VAR''s:
x,y are stored in INITIALISED PART OF DATA SEGMENT.
*p is stored in STACK SEGMENT.

LOCAL VAR''s:
all variables are stored in STACK SEGMENT.

Am I correct? Please correct if i''m wrong.

Cheers & Regards,
Raghu.
HAPPY NEW YEAR-2008



你做了很多关于底层硬件

架构和特定开发的实现细节

系统。如果您想询问有关此类细节的问题,请找一个

相应的新闻组。标准C不保证堆栈

段或者数据段。


-

兰迪霍华德(2个删除FOOBAR)

精确的力量观察被那些没有得到它的人称为玩世不恭。 - George Bernard Shaw

You are making a lot of assumptions about the underlying hardware
architecture and the implementation details of a particular development
system. If you want to ask questions about such specifics, find an
appropriate newsgroup. Standard C makes no guarantees about "stack
segments" or "data segments".

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw


raghu写道:
raghu wrote:

>
>



.... snip ...

.... snip ...


>

据我所知,上述

程序中声明的变量存储如下:

GLOBAL VAR':

x,y存储在数据部分的初始部分。

* p存储在堆栈段中。


LOCAL VAR':

all变量存储在STACK SEGMENT中。


我是否正确?如果我错了,请纠正。
>
According to my knowledge the variables declared in the above
program are stored as follows:
GLOBAL VAR''s:
x,y are stored in INITIALISED PART OF DATA SEGMENT.
*p is stored in STACK SEGMENT.

LOCAL VAR''s:
all variables are stored in STACK SEGMENT.

Am I correct? Please correct if i''m wrong.



错误。 C没有DATA SEGMENT或STACK SEGMENT这样的东西。它b / b
确实有自动存储,静态存储,动态

存储等功能,而这些存储又具有C /> $ b $中所赋予它们的功能b标准。


关于C的一些有用的参考资料:

< http://www.ungerhu.com/jxh/clc.welcome.txt>

< http://www.eskimo.com/~scs/C-faq/top.html(C- faq)

< http:// benpfaff。 org / writings / clc / off-topic.html>

< http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)

< http://cbfalconer.home.att.net/download/n869_txt.bz2(C99,txt)

< http://www.dinkumware。 com / refxc.html(C-library)

< http://gcc.gnu.org/onlinedocs/(GNU docs)

< http:// clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>


-

圣诞快乐,快乐的Hanukah,新年快乐

Joyeux Noel,Bonne Annee,Frohe Weihnachten

Chuck F(cbfalconer at m aineline dot net)

< http://cbfalconer.home.att.net>

-

通过免费的Usenet帐户发布来自 http://www.teranews.com

Wrong. C has no such things as DATA SEGMENT or STACK SEGMENT. It
does have such things as automatic storage, static storage, dynamic
storage, which in turn have the features ascribed to them in the C
standard.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2(C99, txt)
<http://www.dinkumware.com/refxc.html (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com


12月29日下午2:48 * pm,raghu< raghujin ... @ gmail.comwrote:
On Dec 29, 2:48*pm, raghu <raghujin...@gmail.comwrote:

int x;

static int y;

int * p;

int main(无效)

{

int i;

int j = 9;

int * ptr;

char * str =" GOOGLE";

static int a;

int k [];

int q [] = {1,2,3};

注册int reg;

volatile int vol;

......

....

...

返回0;


}


据我所知,变量在以上程序

存储如下:

GLOBAL VAR':

x,y存储在INITIALISED PART OF DATA SEGMENT中。< b r />
* p存储在STACK SEGMENT中。


LOCAL VAR':

所有变量都存储在STACK SEGMENT中。


我说错了吗?如果我错了,请更正。


干杯&此致,

Raghu。

HAPPY NEW YEAR-2008
int x;
static int y;
int *p;
int main(void)
{
int i;
int j=9;
int *ptr;
char *str = "GOOGLE";
static int a;
int k[];
int q[]={1,2,3};
register int reg;
volatile int vol;
......
....
...
return 0;

}

According to my knowledge the variables declared in the above program
are stored as follows:
GLOBAL VAR''s:
x,y are stored in INITIALISED PART OF DATA SEGMENT.
*p is stored in STACK SEGMENT.

LOCAL VAR''s:
all variables are stored in STACK SEGMENT.

Am I correct? Please correct if i''m wrong.

Cheers & Regards,
Raghu.
HAPPY NEW YEAR-2008



为什么指针p在堆栈段中分配?

就我而言,它也应该在Data

段中分配。

why the pointer p allocated in the stack segment?
as far as I am concerned, it should also be allocated in the Data
Segment.


这篇关于Reg:内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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