Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign 1 bit value?

Reading the pthread Library in structure the following is defined:

 struct ptw32_thread_t_
 {
      ....
      int implicit:1;
      ......
 };

I understand that it occupy only 1 bit then how to give value to it as every value assigned with activate the Overflow Error Flags Compiling gives error:

 ptw32_thread_t *sp;
 sp = (ptw32_thread_t *) calloc (1, sizeof(ptw32_thread_t));
 sp->implicit = 1;

 error: overflow in implicit constant conversion [-Werror=overflow]
like image 809
Vineet1982 Avatar asked Jun 03 '16 09:06

Vineet1982


1 Answers

It's a bad idea to have a 1-bit int, since it's a signed type. You can't represent 1 using 1 bit when using signed, you can only represent 0 and -1, which is a bit odd.

The solution is to make it unsigned int implicit : 1.

like image 113
unwind Avatar answered Nov 01 '22 08:11

unwind