C++ 中的位集使用VS2010(另一个)
我刚刚问了另一个关于位集的问题,结果发现这是 VS2010 中的一个错误 使用 VS2010 的 C++ 中的位集
但是,在更改我用于位集的构造函数后,我'遇到了另一个问题(如另一个问题的编辑中所述)
当使用位集的默认构造函数时,它没有被初始化为 0,而是被设置为
[8](0,0,0,0,1,1,0,1)
And _p.to_ulong()
返回 1390560944
这是我刚刚尝试使用 : _p(32)
的代码
class Flags
{
private:
//List of 8 bits
std::bitset<8> _p;
public:
Flags();
}
Flags::Flags()
: _p()
{}
,但这导致设置相同的位如上所述,但是从 to_ulong()
返回的值是 1437615792
这是怎么回事?
编辑:这是在 VS2010 SP1 64 位中编译的,作为 32 位程序
编辑 2:
在下面的评论中,我说我可以在一个简单的程序中复制它 - 我能够复制两次,但从那以后每次都很好 - 也许我只是进展缓慢,这是漫长的一天。
在我的另一个项目(我正在尝试的模拟器)中,我已将其范围缩小到一些函数指针数组。如果我取出它们被赋值的位置,那么我不会得到任何躲避行为,这些数组可以在这里看到
http:// /pastebin.com/QyiJGzNd
该代码将无法编译,因为内存寻址函数不会出现,并且要包含这些函数,我必须包含一堆其他类等。但是为什么要分配函数指针数组的值会影响位集的值吗?位集将在 init()
被调用之前初始化
I just asked another question about bitsets which turns out to be a bug in VS2010
bitsets in C++ using VS2010
However upon changing the constructor I used for the bitset I've run into another problem (as described in the edit of the other question)
When using the default constructor for a bitset, it isn't being initialised to 0's but instead it's being set to
[8](0,0,0,0,1,1,0,1)
And _p.to_ulong()
returns 1390560944
Here's the code
class Flags
{
private:
//List of 8 bits
std::bitset<8> _p;
public:
Flags();
}
Flags::Flags()
: _p()
{}
I also just tried using : _p(32)
but that caused the same bits to be set as above, however the value returned from to_ulong()
is 1437615792
What's going on?
Edit: This is compiled in VS2010 SP1 64 bit, as a 32bit program
Edit 2:
In the comments below, I said I could replicate it in a simple program - I was able to twice but since then it's been fine every time - maybe I was just being slow, been a long day.
In my other project (which is an emulator I'm attempting) I have narrowed it down to some arrays of function pointers. If I take out where they are assigned values then I don't get any dodgey behaviour, those arrays can be seen here
That code won't compile because the memory addressing functions won't be present and to include those I would have to include a bunch of other classes etc etc. But why would assigning values to function pointer arrays affect the values of a bitset? The bitset will be initialised before init()
gets called
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了
我有这个数组(注意索引)
这是在我的作业列表中(注意索引)
我想我刚刚吸取了教训
Solved it
I have this array (note the index)
This is in my assignment list (note the index)
I think I just learnt my lesson