int main () { struct bit{ char f1:1; char f2:1; }; struct bit b; b.f1= 0x1; b.f2 = 0x1; printf("%d\n",b.f1); return 0; }
compiled using gcc code -1 outputs. Shouldn't it be 1? Is it because I compile on a small Entian machine?
Added: during debugging using GDB, I see that the value after initializing the structure elements is -1. that is -1 before printing. The following is a listing from GDB:(gdb) pb$ 7 = {f1 = -1``, f2 = -1 ''}
Let me know if you need additional debug commands. Provide commands for this.
char unsigned signed, . , -, signed, , , int, . , -1 - 11111111 11111111 11111111 11111111 -1 32- int. 1 , 2 2 : 0 1, 0 -1.
char
unsigned
signed
int
EDIT: C 6.2.5, 15: char, char unsigned char . char , , char, char.35
35) CHAR_MIN, limits.h, 0 SCHAR_MIN, . char .
. , 1 , -1.
Skizz tristopia: C99, C, signed unsigned int bool (aka _Bool). - , . , , int, . bool, unsigned, .
unsigned int
bool
_Bool
'unsigned xxxxx'.
[]- , ; - "" "" , , .
. ? 0 1 ( , ). , -1, 0, 1 . - . , , .
int, . ., . . , SO, " "[/]
To 'R.', re: "... , ".
#include <stdio.h> int main () { struct bit{ char f1:1; unsigned char f2:1; }; struct bit b; b.f1 = 1; b.f2 = 1; printf("%d\n",b.f1); printf("%d\n",b.f2); return 0; }
, :
-1 1
, KevinDTimm - , unsigned name:x.
unsigned name:x
, , : . gcc ( unsigned char, :
unsigned char
struct bit { char f1; char f2; };
char (4 ), (1 = neg, 0 = pos). , , . .
, . , , .
. , unsigned int.
I don’t know C. very well. For example, I don’t know what is doing :1in char f1:1, but I managed to get this code to work on my PC by deleting it:
:1
char f1:1
#include <stdio.h> int main () { struct bit{ char f1; char f2; }; struct bit b; b.f1 = 0x1; b.f2 = 0x1; printf("%d\n",b.f1); return 0; }
The result is below:
chooper@brooklyn:~/test$ gcc -o foo foo.c chooper@brooklyn:~/test$ ./foo 1
Hope this helps you!
Source: https://habr.com/ru/post/1771744/More articles:Conjugate matrix correlations in R - how to get through all the pairs? - rsmoothing problem - c #переадресация завершена сделать вывод в файл - unixImport Excel file into SQL Server line by line - c #Создание jQuery tmpl без большого количества тегов script - jqueryCreating jquery templates repeatedly - jqueryString processing EL enum - javaСлужба WCF терпит неудачу каждые 23 часа с "Время ожидания запроса на ожидание ответа после 00:01:00" - asp.netDRY without a single code? - language-agnosticThe parameter of type "POCO Class" in ExecuteFunction is incompatible with the type "EFComplexType" returned by the function - .netAll Articles