Skip to main content
Fixed minor type "with with"
Source Link
Izhaki
  • 23.6k
  • 9
  • 72
  • 107

The same as const int, with with a somewhat stronger typing.

The same as const int, with with a somewhat stronger typing.

The same as const int, with a somewhat stronger typing.

Added reference on R. Chen's article on bitfields
Source Link
paercebal
  • 83.9k
  • 39
  • 135
  • 161

Don't ever use thatDon't ever use that. You are more concerned with speed than with economizing 4 ints. Using bit fields is actually slower than access to any other type.

Source: http://en.wikipedia.org/wiki/Bit_field:

And if you need more reasons to not use bitfields, perhaps Raymond Chen will convince you in his The Old New Thing Post: The cost-benefit analysis of bitfields for a collection of booleans at http://blogs.msdn.com/oldnewthing/archive/2008/11/26/9143050.aspx

Don't ever use that. You are more concerned with speed than with economizing 4 ints. Using bit fields is actually slower than access to any other type.

Source: http://en.wikipedia.org/wiki/Bit_field:

Don't ever use that. You are more concerned with speed than with economizing 4 ints. Using bit fields is actually slower than access to any other type.

Source: http://en.wikipedia.org/wiki/Bit_field:

And if you need more reasons to not use bitfields, perhaps Raymond Chen will convince you in his The Old New Thing Post: The cost-benefit analysis of bitfields for a collection of booleans at http://blogs.msdn.com/oldnewthing/archive/2008/11/26/9143050.aspx

Code corrections
Source Link
paercebal
  • 83.9k
  • 39
  • 135
  • 161

They are still polluting the global namespace, though. By the way... Remove the typedefRemove the typedef. You're working in C++. Those typedefs of enums and structs are polluting the code more than anything else.

enum RecordType { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } RecordType;; void doSomething(RecordType p_eMyEnum) { if(p_eMyEnum == xNew) { // etc. } } 
namespace RecordType { enum Value { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } Value;; } void doSomething(RecordType::Value p_eMyEnum) { if(p_eMyEnum == RecordType::xNew) { // etc. } } 

They are still polluting the global namespace, though. By the way... Remove the typedef. You're working in C++. Those typedefs of enums and structs are polluting the code more than anything else.

enum { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } RecordType; void doSomething(RecordType p_eMyEnum) { if(p_eMyEnum == xNew) { // etc. } } 
namespace RecordType { enum { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } Value; } void doSomething(RecordType::Value p_eMyEnum) { if(p_eMyEnum == RecordType::xNew) { // etc. } } 

They are still polluting the global namespace, though. By the way... Remove the typedef. You're working in C++. Those typedefs of enums and structs are polluting the code more than anything else.

enum RecordType { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } ; void doSomething(RecordType p_eMyEnum) { if(p_eMyEnum == xNew) { // etc. } } 
namespace RecordType { enum Value { xNew = 1, xDeleted, xModified = 4, xExisting = 8 } ; } void doSomething(RecordType::Value p_eMyEnum) { if(p_eMyEnum == RecordType::xNew) { // etc. } } 
Added source for bitfiled slowness.
Source Link
paercebal
  • 83.9k
  • 39
  • 135
  • 161
Loading
Source Link
paercebal
  • 83.9k
  • 39
  • 135
  • 161
Loading