Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 1
    @Neil Butterworth: a) By "evaluated", do you mean that "the result of sizeof would be calculated at compile time and then hard-coded in the executable"? I used to think so, but now I am not able to explain how this works. b) Also, by "not valid" so you mean that it will not run at all or only that the executable will report wrong results? Commented Jun 13, 2010 at 12:03
  • @Lazer It appears to be situational, and likely depends on whether it's possible to determine the size at compile time. A macro such as #define BIT_SIZE(T) (sizeof(T) * CHAR_BIT) can be used as a template parameter for a bitset, such as std::bitset<BIT_SIZE(int)>, while it's determined at run time for C99's variable-length arrays. Commented Mar 28, 2016 at 18:41
  • Or, of course, as std::bitset<BIT_SIZE(someVar)>(someVar), if creating the bitset from a pre-existing variable. Commented Mar 28, 2016 at 18:50