检测全局未初始化变量的读取

编程入门 行业动态 更新时间:2024-10-18 10:22:09
本文介绍了检测全局未初始化变量的读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试检测未初始化的全局变量的读取(在一个文件中声明为,在另一个文件中用作另一个文件)。 我知道ANSI C将所有全局变量初始化为0,但是,我确实不想依赖于此初始化。相反,我想 表达自己初始化所有变量。我看过像 Compuware BoundsChecker这样的工具,它在检测 未初始化变量方面做得非常出色,但是没有检测到GLOBAL的读取 未初始化的变量。 有没有可以做到这一点的工具?或者是否有特定的 技术可用于自动化这个? James

I''m trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however, I do not want to rely on this for initialization. Instead, I want to explicity initialize all variables myself. I''ve looked at tools like Compuware BoundsChecker, which does an amazing job in detecting uninitialized variables, but doesn''t detect reads of GLOBAL uninitialized variables. Is there a tool out there that can do this? Or is there a particular technique that can be used to automate this? James

推荐答案

< jy ******* @ gmail>在消息中写道 news:11 ********************** @ g47g2000cwa.googlegr oups ... <jy*******@gmail> wrote in message news:11**********************@g47g2000cwa.googlegr oups... 我正在尝试检测未初始化的全局变量的读取(在一个文件中声明,在另一个文件中用作extern)。 我知道ANSI C将所有全局变量初始化为0,但是,我不想依赖于此进行初始化。 为什么不呢?语言保证它。 相反,我想明确地自己初始化所有变量。我已经看过像Compuware BoundsChecker这样的工具,它在检测未初始化的变量方面做得非常出色,但是没有检测到GLOBAL 未初始化变量的读取。 那是因为他们*被初始化了。 有没有可以做到这一点的工具?或者是否有一种特殊的技术可用于自动化? I''m trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however, I do not want to rely on this for initialization. Why not? The language guarantees it. Instead, I want to explicity initialize all variables myself. I''ve looked at tools like Compuware BoundsChecker, which does an amazing job in detecting uninitialized variables, but doesn''t detect reads of GLOBAL uninitialized variables. That''s because they *are* initialized. Is there a tool out there that can do this? Or is there a particular technique that can be used to automate this?

你需要某种C解析器。 -Mike

You''ll need some kind of C parser. -Mike

" Mike Wahler" < MK ****** @ mkwahler>在消息中写道 新闻:jJ **************** @ newsread3.news.pas.earthli nk ... "Mike Wahler" <mk******@mkwahler> wrote in message news:jJ****************@newsread3.news.pas.earthli nk... < jy ******* @ gmail>在消息中写道新闻:11 ********************** @ g47g2000cwa.googlegr oups ... <jy*******@gmail> wrote in message news:11**********************@g47g2000cwa.googlegr oups... 我正在尝试检测未初始化的全局变量的读取(在一个文件中声明,在另一个文件中用作extern)。 ....有没有可以做到这一点的工具?或者是否有一种特殊的技术可用于自动化? I''m trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). .... Is there a tool out there that can do this? Or is there a particular technique that can be used to automate this?

你需要某种C解析器。

You''ll need some kind of C parser.

如果这些变量被分组到一个特殊的部分,那么可能可以在每次访问该部分所在的页面时捕获这些变量 。它可能不容易做到b $ b,或者如果你有很多变量,那么很难找到所有的东西,并且每次都需要停止...只是一个想法... Alex

If these variables are grouped into a special section, it might be possible to trap on each and every access to the pages in which the section lies. It may not be easy to do, though, or not easy to find everything if you have many variables in there and need to stop every time... Just an idea... Alex

2005年9月30日星期五03:53:22 +0400,Alexei A .Frounze < al ***** @ chat.ru>在comp.lang.c中写道: On Fri, 30 Sep 2005 03:53:22 +0400, "Alexei A. Frounze" <al*****@chat.ru> wrote in comp.lang.c: " Mike Wahler" < MK ****** @ mkwahler>在消息中写道新闻:jJ **************** @ newsread3.news.pas.earthli nk ... "Mike Wahler" <mk******@mkwahler> wrote in message news:jJ****************@newsread3.news.pas.earthli nk... < jy*******@gmail>在消息中写道新闻:11 ********************** @ g47g2000cwa.googlegr oups ... <jy*******@gmail> wrote in message news:11**********************@g47g2000cwa.googlegr oups... 我正在尝试检测未初始化的全局变量的读取(在一个文件中声明,在另一个文件中用作extern)。 ......有没有可以做到这一点的工具?或者是否有一种特殊的技术可用于自动化?你需要某种C解析器。 I''m trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). ... Is there a tool out there that can do this? Or is there a particular technique that can be used to automate this? You''ll need some kind of C parser.

如果这些变量是分组的进入一个特殊的部分,可能会陷入对每个部分所在页面的每次访问。它可能不容易做到,或者如果你有很多变量并且每次都需要停止而不容易找到所有的东西......只是一个想法...... Alex

If these variables are grouped into a special section, it might be possible to trap on each and every access to the pages in which the section lies. It may not be easy to do, though, or not easy to find everything if you have many variables in there and need to stop every time... Just an idea... Alex

引用Alexei A. Frounze <人***** @ chat.ru>在comp.lang.c中: 这是关于comp.lang.c的主题。 Alex

To quote "Alexei A. Frounze" <al*****@chat.ru> in comp.lang.c: This is off topic for comp.lang.c. Alex

我''我无法在8051上运行一个C程序实现你的建议 。 你的答案与标准C有什么关系? br /> 没有''特殊部分''或''页''? - 杰克克莱恩 主页: JK-Technology.Com 常见问题解答 comp.lang.c www.eskimo/~scs/C-faq/top.html comp.lang.c ++ www.parashift/c++-faq-lite/ altp.lang.learn.c-c ++ www.contrib.an drew.cmu.edu/~a...FAQ-acllc.html

I''m having trouble implementing your suggestion on a C program running on an 8051. And what does your answer have to do with standard C, which knows nothing of ''special sections'' or ''pages''? -- Jack Klein Home: JK-Technology.Com FAQs for comp.lang.c www.eskimo/~scs/C-faq/top.html comp.lang.c++ www.parashift/c++-faq-lite/ altp.lang.learn.c-c++ www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

更多推荐

检测全局未初始化变量的读取

本文发布于:2023-07-28 02:32:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1226487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   全局   变量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!