全局变量:它们存储在哪里? [英] Global Variables : Where are they stored ?

查看:128
本文介绍了全局变量:它们存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于全局

变量的存储,以下哪项是正确的:

1.全局变量存在于
之前的存储区中
首次引用

直到最后一次引用之后的程序。

2.初始化数据段中存在全局变量。

解决方案

文章

< d5 ************************ ********** @ s36g2000prg。 googlegroups.com>,

Kislay< ki *********** @ gmail.comwrote于2007年11月27日星期二晚上8:40发表:


关于全局

变量的存储,以下哪项是正确的:

1.全局变量存在于以前存在的内存区域中

程序中的第一个引用直到最后一个引用之后。



C标准表示在程序启动之前创建并初始化文件范围对象

并存在直到程序终止。所以

上面的陈述是不真实的。


2.全局变量存在于初始化的数据段中。



C标准没有定义段。或数据段。它说

然而文件范围对象(有或没有外部链接)和

那些被声明为静态的程序在程序之前初始化一次

start -up。如果没有提供明确的初始化,则将它们初始化为

为零。


Kislay写道:


>

关于全局

变量的存储,以下哪项是正确的:

1。全局变量存在于一个存储区中,该区域存在于程序之前的

第一个引用

之前,直到最后一次引用之后。

2.Global变量存在于初始化的数据段中。



大多数人所说的特殊记忆方面

byGlobal variables"是对象有静态持续时间。

这些对象在主要开始执行之前初始化

并持续到程序终止。


数据段可能会或可能不会成为您计算机上实施C的方式的一部分

但是数据段

isn'' ta编程语言的概念。


-

pete


santosh写道:


文章

< d5 ********************** ************ @ s36g2000prg。 googlegroups.com>,

Kislay< ki *********** @ gmail.comwrote于2007年11月27日星期二晚上8:40发表:


>关于全局变量的存储,以下哪项是正确的:
1。全局变量存在于存储区中,该存储区从程序中的第一个引用之前到最后一个引用之后存在。



C标准表示在程序启动之前创建并初始化文件范围对象

并存在直到程序终止。所以

上面的陈述是不真实的。



无论如何,严格符合程序是否在第一次引用之前检测

内存是否存在?同样地,

无论如何都要在

最后一次引用之后检测内存是否仍然存在?我不知道有什么方法可以这样做,所以as-if

规则会使这两个关于对象生命周期的陈述彼此兼容



Which of the following is correct regarding the storage of global
variables :
1. Global variables exist in a memory area that exists from before the
first reference
in a program until after the last reference .
2.Global variables exist in the initialized data segment .

解决方案

In article
<d5**********************************@s36g2000prg. googlegroups.com>,
Kislay <ki***********@gmail.comwrote on Tuesday 27 Nov 2007 8:40 pm:

Which of the following is correct regarding the storage of global
variables :
1. Global variables exist in a memory area that exists from before the
first reference in a program until after the last reference .

The C standard says that file scope objects are created and initialised
just before program start-up and exist till the program terminates. So
your statement above is untrue.

2.Global variables exist in the initialized data segment .

The C standard does not define a "segment" or a "data segment". It says
however that file scope objects (with or without external linkage) and
those declared as static are initialised once prior to program
start-up. If no explicit initialiser is provided, they are initialised
to zero.


Kislay wrote:

>
Which of the following is correct regarding the storage of global
variables :
1. Global variables exist in a memory area that exists from before the
first reference
in a program until after the last reference .
2.Global variables exist in the initialized data segment .

The aspect of memory that is special to what most people mean
by "Global variables" is that the objects have static duration.
Such objects are initialized before main starts executing
and persist to the termination of the program.

"data segment" may or may not be part of the way
that C is implemented on your machine,
But "data segment"
isn''t a concept of the C programming language.

--
pete


santosh wrote:

In article
<d5**********************************@s36g2000prg. googlegroups.com>,
Kislay <ki***********@gmail.comwrote on Tuesday 27 Nov 2007 8:40 pm:

>Which of the following is correct regarding the storage of global
variables :
1. Global variables exist in a memory area that exists from before the
first reference in a program until after the last reference .


The C standard says that file scope objects are created and initialised
just before program start-up and exist till the program terminates. So
your statement above is untrue.

Is there anyway for a strictly conforming program to detect whether the
memory exists before the first time that it is referenced? Similarly, is
there anyway for to detect whether the memory still exists after the
last reference to it? I''m not aware of any way to do so, so the as-if
rule would make these two statements about object lifetime compatible
with each other.


这篇关于全局变量:它们存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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