Как установить/отключить значение перечисления для чего-то вроде следующего. Использование GCC, я получаю это раздражает предупреждение:отрицательное целое, неявно преобразованное в неподписанный тип
test.c:37: warning: negative integer implicitly converted to unsigned type
test.c:39: warning: negative integer implicitly converted to unsigned type
test.c:41: warning: negative integer implicitly converted to unsigned type
test.c:43: warning: negative integer implicitly converted to unsigned type
код:
#include <stdio.h>
#include <string.h>
typedef enum {
ONE = 0x1,
TWO = 0x2,
THREE = 0x4,
FOUR = 0x8,
} options;
static const char *byte_to_binary (int x)
{
int z;
static char b[9];
b[0] = '\0';
for (z = 256; z > 0; z >>= 1)
{
strcat(b, ((x & z) == z) ? "1" : "0");
}
return b;
}
int main(int argc, char *argv[])
{
options o = 0;
printf("%s\n", byte_to_binary(o));
o |= ONE;
printf("%s\n", byte_to_binary(o));
o |= TWO;
printf("%s\n", byte_to_binary(o));
o |= THREE;
printf("%s\n", byte_to_binary(o));
o |= FOUR;
printf("%s\n", byte_to_binary(o));
o &= ~FOUR;
printf("%s\n", byte_to_binary(o));
o &= ~THREE;
printf("%s\n", byte_to_binary(o));
o &= ~TWO;
printf("%s\n", byte_to_binary(o));
o &= ~ONE;
printf("%s\n", byte_to_binary(o));
return 0;
}
Пожалуйста, укажите номер строки. –
Это может быть полезно: http://stackoverflow.com/questions/2579230/signedness-of-enum-in-c-c99-c-cx-gnu-c-gnu-c99 – bmartins