首页 | 本学科首页   官方微博 | 高级检索  
相似文献
 共查询到19条相似文献,搜索用时 250 毫秒
1.
引用是给某个对象(包括变量)起的别名,因此它不能独立存在,这一点与指针不同,指针可以不指向任何对象。C++要求说明引用时必须初始化,即与某个对象联系起来,这种联系是不能改变的。同一对象可以同时有多个引用,对象与引用的关系为1∶n(n≥0)。 引用作为函数参数时,表明该参数是变量参数,而不是值参数;指针作为函数参数时,只是模拟变量参数。在很多应用中,指针和引用是可以相互取代的,C++编译器内部就是把引用作为指针处理的。当然引用有其独特的用途,否则C++就不会引进它了,但如果没有正确理解引用的概念,在编程时会给程序员带来一些迷惑。 C++要求非单目运算符以友元身份重载时,其  相似文献   

2.
指针指针是C语言中的一个重要概念,指针类型数据在C语言程序中的使用十分普遍。C语言区别于其它程序设计语言的主要特点就是处理指针时所表现出的能力和灵活性。正确地使用指针类型数据,可以有效地表示复杂的数据结构,直接处理内存地址,而且可以更为有效合理地使用数组。一、指针与地址计算机程序的指令、常量和变量等都要存放在以字节为单位的内存单元中,内存的每个字节都具有一个唯一的编号,这个编号就是存储单元的地址。各个存储单元中所存放的数据,称为该单元的内容。计算机在执行任何一  相似文献   

3.
指针是C语言的精髓.灵活正确的使用指针可以使程序得到优化.巧妙的利用指针又可以达到特殊的目的.本文利用字符型的指针指向了其他类型的变量,以读取变量所占内存的每个字节的内容.由此验证数据在内存中的存储方式.  相似文献   

4.
张广梅  李景霞 《计算机科学》2015,42(Z11):504-507
应用程序中的功能通常是通过对变量的操作来实现。应用程序中变量的操作包括赋值、引用等不同的方式。针对普通变量和指针变量在程序中的使用方式,对变量的状态进行了分析,并根据变量使用的特点,定义了普通变量和指针变量的状态转换模型。在此基础上,给出了与变量有关的软件错误的定义,并讨论了基于变量切片的软件错误的检测方法。  相似文献   

5.
使用C语言编程经常会使用各类指针,指针的使用带来了便利,但是不当的使用也会带来灾难,对指针的验证,是重点也是难点.主要介绍软件单元测试阶段验证指向变量的指针、指向结构体的指针、指向函数的指针、多重嵌套指针等常见指针的方法.  相似文献   

6.
1.问题分析 C语言中变量定义的实质(或目的),是为了在编译时能为其分配相应的存储单元。同时,C语言又提供了指针机制,允许使用指针对内存单元进行操作。而且,C语言经编译后,取得并使用四个逻辑上不同、且用于不同对象的内存区域,它们分别是:栈、堆、全局变量区、程序代码区,其中“堆”是一个自由内存区域,C语言可通过内存分配函数(malloc()、calloc()),动态地从中获得所需空间。由指针指向被分配的内存块,其  相似文献   

7.
指针是C语言中一种重要的数据类型 ,学习C语言若不学好指针数据类型 ,就不能更好地掌握C语言的精华。近几年笔者在从事C语言教学中发现很多同学在学习指针时非常困难 ,而且往往处于一知半解。笔者将从以下几个方面来阐述C语言中的指针这一数据类型。1 指针与指针变量  所谓指针 ,英文单词为point,也就是变量的地址 ;而指针变量则是用于存放地址值的量。可见指针类型的数据和平常所说的整型、浮点型等数据一样 ,它也是一种数据类型。指针变量 ,和其它类型变量相同 ,在计算机内同样也占有存储单元 ,不同的是这种类型的变量存放的…  相似文献   

8.
一、引言指针是C语言中的一个重要的特殊变量,与一般变量不同之处是它包含的不是数据的值,而是另一个变量的地址。使用指针可设计出紧凑、清晰和高效的程序,有时使用指针还是实现某些算法的唯一方法。然而,在C语言编程中,指针的使用很容易出错。笔者经过几年的教学和科研实践,总结出了一点经验,供有兴趣的同志参考。二、常见错误分析 1.未给指针分配空间使用指针时,一个最容易犯的错误,就是在为指针变量分配存储空间前,对其指向的空间进行赋值操作。如下述程序段:  相似文献   

9.
C语言中指针系指以字节为单位的一段内存区域的起始地址。存储该起始地址的变量即为指针变量。比如:intx,*P=&x;定义了一个整型变量x(对应一段2字节的内存区域)及一个指向X的指针变量p(p中存放该内存区域的起始地址)。因此,一个指针变量的值就是该指针变量所指向的内存区域的起始地址。这个起始地址是指针变量所包含的一个众所周知的信息。但仅有起始地址,是不能确定指针变量及其所指向内存区域的对应关系的。所缺少的实际上就是内存区域的长度,而这正是指针变量的另一个不为人们所注目的信息。互指针变量的内存区域长度信息指…  相似文献   

10.
针对现有可信指针分析技术中关于精度和效率之间的取舍和权衡的不足,提出一种需求驱动的可信指针分析技术。该技术通过扩展SSA形式,使SSA可以用来表示间接的内存操作,即可以显式地将指针的解引用表示出来;之后利用引用定值分析将每个扩展SSA变量进行抽象存储,即记录每个变量的存储位置和引用位置,然后通过链进行连接;这样能够很容易地将指针,特别是需要分析的指针进行重点的有针对性的分析,这种本着需求驱动策略的分析方法大大提高分析的效率,最后通过实验验证了该方法的有效性。  相似文献   

11.
C语言是一门面向用户的过程语言,指针是该语言中最为灵活的一部分.汇编语言是一门面向处理器的过程语言,该语言中没有指针的明确定义,但指针的概念却随处可见.本文通过间接寻址方式引出指针在汇编语言中的应用,借助存储空间图深入探悉C语言中的指针和汇编语言中的间接寻址的密切关系,用一个全新的概念更好的去理解指针在这两门语言中的应用和联系.  相似文献   

12.
The use of pointers presents serious problems for software productivity tools for software understanding, restructuring, and testing. Pointers enable indirect memory accesses through pointer dereferences, as well as indirect procedure calls (e.g., through function pointers in C). Such indirect accesses and calls can be disambiguated with pointer analysis. In this paper we evaluate the precision of one specific pointer analysis (the FA pointer analysis by Zhang et al.) for the purposes of call graph construction for C programs with function pointers. The analysis is incorporated in a production-strength code-browsing tool from Siemens Corporate Research in which the program call graph is used as a primary tool for code understanding.The FA pointer analysis uses an inexpensive, almost-linear, flow- and context-insensitive algorithm. To measure analysis precision, we compare the call graph constructed by this analysis with the most precise call graph obtainable by a large category of existing pointer analyses. Surprisingly, for all our data programs the FA analysis achieves the best possible precision. This result indicates that for the purposes of call graph construction, inexpensive pointer analyses may provide precision comparable to the precision of expensive pointer analyses.  相似文献   

13.
古辉  乔凯旋 《计算机系统应用》2012,21(7):236-239,253
研究了C++中的指针机制、以及指针类型对象(变量)在多个源程序代码文件中关联关系。基于信息提取和结果整理,计算机可视化实现和表示C++中的指针机制和多源程序代码文件的关联关系。研究了抽取结果的存储机制和基于该机制的自动排序源文件引用关系的方法,最后提出了一种手工调整图元布局的算法,作为自动排序算法的补充。对实际代码分析的结果表明该方法利于程序分析并支持对源代码的辅助理解。  相似文献   

14.
从变量的初始化中获取指针指向信息完整的指针分析不可缺少的一个重要环节,它有助于提高其它数据流分析的准确性,文中提出了一个实用的从变量的初始化中获取指针同信息的方法,在此方法中,变量的初始化首先被转换成语义等价的语句序列,然后在指针分析的过程中融入对这些语句序列的分析而求取出相关的指针指向信息,这个方法被实现天复旦大学并行处理研究开发的C程序分析工具Agassiz系统内,实验数据说明是非常有效。  相似文献   

15.
This paper describes a way of expressing λ-expressions (which produce closures) in terms of ε-expressions (λ-expressions containing only local and global variable references) and calls to an interactive compiler that compiles ε-expressions. This point of view is an interesting way of describing the semantics of λ-expressions and closure generation. It also leads to an efficient closure implementation both in time and space. A closure is uniformly represented as a piece of code instead of a compound object containing a code and environment pointer. This method can also be used to simulate closures in conventional dialects of Lisp  相似文献   

16.
标准模版库提供了一系列的容器类型,使用容器可以完成任意类型对象的不限量存储。任何模版类型中均包含迭代器类型,使用迭代器类型可以完成统一的指针操作,读写容器内的数据。不同模版具有不同的存储结构,实际应用中存在性能差异。  相似文献   

17.
This paper describes an implementation method for object-oriented applications. In the common practice the base address of the current object instance is passed on the stack as a pointer from one virtual method to another. The way suggested in this paper uses a global pointer pointing to the currently active object. This pointer is implemented by using some of the CPU registers exclusively for this purpose, thus saving the time of reloading it. Provided that some instructions manipulate on the same object instance before the program switches to another object a smaller and faster executing code can be achieved and at the same time some stack space can be saved.  相似文献   

18.
《Ergonomics》2012,55(6):469-474
A variable liable to affect display-control relationships is treated in this article. It is shown that the strength of the stereotype known as Warrick's Principle, the expectation that a pointer will move in the same direction as that part of the control nearest to the display, is reduced as the pointer is set off to either side of the control knob. In an arrangement with the knob above a horizontal display this reduction may cause a reversal of an operator's expectation of directional relationship at a pointer position not very far from the knob. It is maintained, however, that this effect of pointer position is not likely to influence expectation in an unambiguous arrangement of display and control.  相似文献   

19.
In the study of random access machines (RAMs) and the complexities associated with their algorithms, the availability of indirect addressing often creates an analysis obstacle. We show that for RAMs equipped with a sufficiently rich set of basic operations, indirect addressing does not increase computational power, and can be simulated either in linear time or on-line in real time. These results pertain to the uniform cost model and, particularly, assume a unit cost variable shift.  相似文献   

设为首页 | 免责声明 | 关于勤云 | 加入收藏

Copyright©北京勤云科技发展有限公司  京ICP备09084417号