In the following example, can I define the size of a C element in bits?
#include <stdio.h>
typedef enum {
false = 0,
true = ~0
} bool;
int main(void) {
bool x;
printf("%d", sizeof x);
return 0;
}
In the following example, can I define the size of a C element in bits?
#include <stdio.h>
typedef enum {
false = 0,
true = ~0
} bool;
int main(void) {
bool x;
printf("%d", sizeof x);
return 0;
}
In general, no. The minimum addressable unit is a byte, not a bit.
You can do funny things with bitfields, such as:
struct {
unsigned a : 31;
unsigned b : 1;
};
That struct will likely have a sizeof == 4
, a
will use 31 bits of space, and b
will use 1 bit of space.
enum
is of int size. All i need to do is make the implicit cast explicit.
#include <stdio.h>
typedef enum {
true = ~(int)0,
false = (int)0
} bool;
int main(void) {
return false;
}