title: Can I allocate a specific number of bits in C?
body: <p>I am trying to store a large amount of boolean information that is determined at run-time.  I was wondering what the best method might be.</p>
  
  <p>I have currently been trying to allocate the memory using: </p>
  
  <p><code>pStatus = malloc((&lt;number of data points&gt;/8) + 1);</code> </p>
  
  <p>thinking that this will give me enough bits to work with.  I could then reference each boolean value using the pointer in array notation:</p>
  
  <p><code>pStatus[element]</code></p>
  
  <p>Unfortunately this does not seem to be working very well.  First, I am having difficulty initializing the memory to the integer value <code>0</code>.  Can this be done using <code>memset()</code>?  Still, I don't think that is impacting why I crash when trying to access <code>pStatus[element]</code>. </p>
  
  <p>I am also not entirely convinced that this approach is the best one to be using.  What I really want is essentially a giant bitmask that reflects the status of the boolean values.  Have I missed something?</p>