std :: cout腐败变量

时间:2017-11-18 18:37:24

标签: c++ cout corruption

简短版本:我有一个名为" number"的变量。 (真的),我打印的东西不使用该变量,然后在打印功能中更改(由gdb检查)。

长版:以下是一些代码段:

cpu.cpp:

//...
unsigned char Cartridge::getMem(unsigned short addr) {return (*mapper).getMem(addr);}
//...

cart.cpp:

//...
unsigned char Mapper::getMem(unsigned short addr) {
    switch(number) {
        case 4:
        if(addr >= 0xE000) {
            unsigned int prgLocation = (((unsigned int)parent.prgSize) << 14) + addr;
            std::cout << "MAPPED INPUT ADDRESS " << "0x" << std::setw(4) << addr << " TO PRG ROM ADDRESS " << "0x" << std::setw(4) << prgLocation << ". \n";
            return parent.prg[prgLocation];
        } else {
            std::cerr << "ERROR: I DON'T RECOGNIZE ANYTHING AT ADDRESS " << "0x" << std::setw(4) << addr << "!\n";
            exit(3);
        }
        break;
        default:
        std::cerr << "ERROR: UNRECOGNIZED MAPPER " << "0x" << std::setw(2) << ((int)number) << "!\n";
        exit(2);
    }
}

mapper.cpp:

#ifndef CART_HPP
#define CART_HPP
//...
class Mapper {
    private:
        unsigned short number;
        Cartridge parent;
    public:
        Mapper(Cartridge* cart, unsigned short number);
        unsigned char getMem(unsigned short addr);
        void setMem(unsigned short addr, unsigned char value);
        ~Mapper();
};
#endif

cart.h(也包含Mapper):

MAPPED INPUT ADDRESS 0xFFFC TO PRG ROM ADDRESS 0x4FFFC.

初始化使用的所有变量。 &#34;(* cart.mapper)。数&#34;在初始化CPU之前设置为4,但是,在运行时,首先输出:

ERROR: UNRECOGNIZED MAPPER 0xFC5C!

正如预期的那样(我在Mapper初始化程序中有一些格式化命令)。什么是不对的,就在下一次调用之后说:

$ composer require sensio/framework-extra-bundle "3.0.12"

$ composer require friendsofsymfony/rest-bundle 1.8

这似乎表明&#34;数字&#34;已经变了。在gdb中运行表示&#34; number&#34;变得内在,但为什么? (另外,gdb说映射器0xFADC,这也很神秘。)正如你所看到的,&#34;数字&#34;没有被传递到函数中。

我正在运行最新的MinGW32,我可以通过Windows 10 64位上的最新MSYS。

0 个答案:

没有答案