Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The boolean is "never" a separate value in C. So a struct might be in order to get you going.</p> <p>It is true that you do not initialize the mem area so you need to do that individually.</p> <p>Here is a simple example of how you could do it with unions structs and enums</p> <pre><code>typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long int DWORD; typedef unsigned long long int DDWORD; enum STATUS { status0 = 0x01, status1 = 0x02, status2 = 0x04, status3 = 0x08, status4 = 0x10, status5 = 0x20, status6 = 0x40, status7 = 0x80, status_group = status0 + status1 +status4 }; #define GET_STATUS( S ) ( ((status.DDBuf&amp;(DDWORD)S)==(DDWORD)S) ? 1 : 0 ) #define SET_STATUS( S ) ( (status.DDBuf|= (DDWORD)S) ) #define CLR_STATUS( S ) ( (status.DDBuf&amp;= ~(DDWORD)S) ) static union { BYTE BBuf[8]; WORD WWBuf[4]; DWORD DWBuf[2]; DDWORD DDBuf; }status; int main(void) { // Reset status bits status.BBuf[0] = 0; printf( "%d \n", GET_STATUS( status0 ) ); SET_STATUS( status0 ); printf( "%d \n", GET_STATUS( status0 ) ); CLR_STATUS(status0); printf( "%d \n", GET_STATUS( status0 ) ); SET_STATUS( status_group ); printf( "%d \n", GET_STATUS( status0 ) ); system( "pause" ); return 0; } </code></pre> <p>Hope this helps. This example can handle up until 64 status booleans and could be easy extended.</p> <p>This exapmle is based on Char = 8 bits int = 16 bits long int = 32 bits and long long int = 64 bits</p> <p>I have now also added support for status groups.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload