English 中文(简体)
记忆中储存的ool型变量如何? (C++)
原标题:How a bool type variable is stored in memory? (C++)
  • 时间:2011-11-01 14:24:26
  •  标签:
  • c++
  • boolean

bool检测;

sizeof(test) = 1 if using VS 2010. Since every C++ data type must be addressable, the "test" bool variable is 8-bits(1 byte).

我的问题是,“测试”在记忆中实际上占了1个。

Is there any implementation skill that can make the bool data type occupy only one bit? If yes, can you give me an example?

bool test1[32](in VS 2010), int test2(in VS 2010)

http://www.ohchr.org。 占领同样的记忆?

问题回答

<代码>试验1的每个要素必须予以处理。 这意味着test1 (使用<代码>bool测试1 [32]创建)至少需要32个tes(每个元素1个 by)。

如果你想要将多种生物价值储存在一个单一变量中,使用<代码>std:bitset<>>> 或std:vector<bool>(但认识到后者实际上不是羊毛的载体),则是一种专门设计,可以节省空间。

IIRC, C++11还界定了std:dynamic_bitset

My question is that does the "test" variable really occupy 1 byte in memory?

Yes, if sizeof(bool)==1 . Basically, the sizeof bool is implementation-defined, which means it could be greater than 1 byte for certain compiler.

bool test1[32](in VS 2010), int test2(in VS 2010)
Does test1 and test2 occupy the same memory?

他们所占领的每一种东西都可以通过使用经营者的规模来知道。 这就是经营者的规模。 www.un.org/spanish/ga/president

另一种变数为1比2, 即:

struct {
    int a:1;
    int b:1;
};




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签