Napisałem program który zlicza bity ustawione i nieustawione - poprawnie. Niestety wywala mi na testach taki oto błąd i nie wiem jak sobie z tym poradzić :(
functions.h:35:57: error: lvalue required as left operand of assignment
for (*pointer_to_bits_set_counter = 0; value; value >>= 1)\
^~~
unit_test_v2.c:2905:13: note: in expansion of macro ‘COUNT_BITS’
COUNT_BITS(79 + 33, &bits_set, &bits_cleared);
^~~~~~~~~~
functions.h:35:57: error: lvalue required as left operand of assignment
for (*pointer_to_bits_set_counter = 0; value; value >>= 1)\
^~~
unit_test_v2.c:2911:13: note: in expansion of macro ‘COUNT_BITS’
COUNT_BITS(79 + 33, &bits_set, &bits_cleared);
KOD:
#define COUNT_BITS(value, pointer_to_bits_set_counter, pointer_to_bits_cleared_counter){\
for (*pointer_to_bits_set_counter = 0; value; value >>= 1)\
*pointer_to_bits_set_counter += value & 1;\
int zm=sizeof(value); * pointer_to_bits_cleared_counter=zm*8-*pointer_to_bits_set_counter ;\
}
wywołanie:
unsigned int liczba;
unsigned int* wow = &liczba;
if (scanf("%u", wow) != 1)
{
printf("Incorrect input"); return 1;
}
COUNT_BITS(*wow, wa, wb);
printf("%d\n%d", *wa, *wb); printf("\n");