对Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.的处理以及理解

对于这个问题,我们先来看一个简单的C程序:

#include <stdio.h>

void Fun1()
{
    int a = 48;
}

void Fun2()
{
    int a;
    printf("%d\n",a);
}

int main()
{
    Fun1();
    Fun2();

    return 0;
}

你们猜猜运行结果是什么?在VS下直接崩溃。。。
然后我又用VC和Linux下GCC测试,结果分别为-858993460和随机值。
于是。。。(懵逼)

通过分析,发现这与RTC(Run-Time Check,运行时检查)机制有关(以下都是以VS2012为标准)。
首先普及一下RTC(Run-Time Check)机制,包括堆栈帧(RTCS)、未初始化变量(RTCu)、两者都有、以及默认值四种。
在VS2012编译器中,项目-》属性-》配置属性-》C/C++ -》生成代码-》基本运行时检测 下有。
1.当开启RTCu(对未初始化变量运行时的检查)时,程序会崩溃。提示错误RTC Failure#3:使用了未初始化的变量
2.当开启RTCs(对堆栈帧运行时的检查)时,可以运行,结果为固定值,针对以上程序,结果为-858993460(%d打印),0xcccccccc(%#x打印)。实际上调用Fun2()开辟新栈帧时,栈帧被0xcc初始化,打印出来的结果如上。
3.当两者都开启时,与情况一一样,程序崩溃。提示错误RTC Failure#3:使用了未初始化的变量
4.当使用默认值时,程序可以运行,结果为相对应位置的值。例如本程序中结果为48,若程序Fun1()函数中只有一个变量,值为多少,结果就为多少。说白了,函数Fun2()中变量a的值与其本身无关,而与相对应的内存中存放的值有关。原因是默认值这种模式,当有新的栈帧开辟时,不会有0xcc这个初始化的过程。
以下为本人对如上问题的理解,如有偏颇,希望同仁批评指正,谢谢!

  • 22
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
NEWS for OpenSC -- History of user visible changes Complete change history is available online: http://www.opensc-project.org/opensc/timeline New in 0.12.0; 2010-12-22 * OpenSC uses a single reader driver, specified at compile time. * New card driver: Italian eID (CNS) by Emanuele Pucciarelli. * New card driver: Portuguese eID by Jo茫o Poupino. * New card driver: westcos by Fran莽ois Leblanc. * pkcs11-tool can use a slot based on ID, label or index in the slot list. * PIN flags are updated from supported cards when C_GetTokenInfo is called. * Support for CardOS 4.4 cards added. * Fature to exclude readers from OpenSC PKCS#11 via "ignored_readers" configuration file entry. * #229: Support semi-automatic fixes to cards personalized with older and broken OpenSC versions. * Software keys removed from pkcs15-init and the PKCS#11 module. OpenSC can either generate keys on card or import plaintext keys to the card, but will never generate plaintext key material in software by itself. All traces of a software token (PKCS#15 Section 7) shall be removed. * Updates to PC/SC driver to build with pcsc-lite >= 1.6.2 * Build script for a binary Mac OS X installer for 10.5 and 10.6 systems. Binary installer includes OpenSC.tokend for platform integration. 10.6 installer includes engine_pkcs11. * Modify Rutoken S binary interfaces by Aktiv Co. * Support GOST R 34.10-2001 and GOST R 34.11-94 by Aktiv Co. * CardOS driver now emulates sign on rsa keys with sign+decrypt usage with padding and decrypt(). This is compatible with old cards and card initialized by Siemens software. Removed "--split-key" option, as it is no longer needed. * Improved debugging support: debug level 3 will show everything except of ASN1 and card matching debugging (usualy not needed). * Massive changes to libopensc. This library is now internal, only used by opensc-pkcs11.so and command line tools. Header files are no longer installed, library should not be used by other applications.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值