我正在尝试将 unsigned char 变量的一位更改为 1。不过,我一直遇到分段错误。这是失败的代码片段:
unsigned char bitvector[16];
int addbit(unsigned char *bitv,int bit){
int a = bit/CHAR_BIT; //part of char array we want. CHAR_BIT is 8
bitv[a] |= 1 <<bit;
return 1
}
...
if(checkbit(pointer->bitvector,i)==0){
//checkbit works great! bitv[0] has the value of 71,
//a turns to be 0 when I call it
addbit(pointer->bitvector,i);
编译:make:*** [all] 分段错误(核心转储)