| | _Bool
时间: 2024-02-10 15:13:00 浏览: 199
_Bool是C99标准中新增的一种基本数据类型,它只有两个取值,即0和1,分别代表false和true。_Bool类型可以直接进行逻辑运算,例如与(&&)、或(||)、非(!)等运算。
在C语言中,_Bool类型可以通过以下方式进行定义:
```c
_Bool bool_var; // 使用_Bool关键字定义_Bool类型的变量
```
需要注意的是,在C语言中,_Bool类型的变量只占用1个字节的存储空间,因此它的取值只能是0或1,不能是其他的整数值。
相关问题
#include "black.h" #include<iostream> using namespace std; class black { int chessman_X; //横向位置 int chessman_Y; //纵向位置 int black_chessman_count; //落子总数 int black_chessmanplayer; public: black() { black_chessman_count = 0; black_chessmanplayer = -1; } bool submit_chessman(int chessman_X, int chessman_Y) { if (chessman_X > 15 || chessman_X < 1 || chessman_Y>15 || chessman_Y < 1) { return false; } else { this->chessman_X = chessman_X; this->chessman_Y = chessman_Y; black_chessman_count++; return true; } } int getIdentity() { return black_chessmanplayer; } int getChessman_X() { return chessman_X - 1; //这里设置减一是因为画图从0位置开始 } int getChessman_Y() { return chessman_Y - 1; } int getChessmanCount() { return black_chessman_count; } }; 根据这个CPP写出.h
#ifndef BLACK_H
#define BLACK_H
class black
{
private:
int chessman_X; //横向位置
int chessman_Y; //纵向位置
int black_chessman_count; //落子总数
int black_chessmanplayer;
public:
black();
bool submit_chessman(int chessman_X, int chessman_Y);
int getIdentity();
int getChessman_X();
int getChessman_Y();
int getChessmanCount();
};
#endif // BLACK_H
//black list bool isLhdcBlacklist = false; isLhdcBlacklist = interop_mtk_match_addr_name(INTEROP_MTK_A2DP_DISABLE_LHDC_CODEC, &peer_address); //Choose bool lhdc_flag = false; if (isLhdcCodec && (A2DP_VendorCodecGetCodecId(p_codec_info) == A2DP_LHDCV5_CODEC_ID)) { switch (strcmp(lhdcv5_support, "false")) { case 0: if (!isLhdcWhitelist || !btif_av_get_lhdc_codec_state()) { lhdc_flag = true; } break; default: if (isLhdcBlacklist || !btif_av_get_lhdc_codec_state()) { lhdc_flag = true; } break; } }优化这段代码
这段代码可以进行如下优化:
1. 将变量声明和初始化放在一行,更加简洁:
```
bool isLhdcBlacklist = interop_mtk_match_addr_name(INTEROP_MTK_A2DP_DISABLE_LHDC_CODEC, &peer_address);
bool lhdc_flag = false;
```
2. 将 case 0 的情况提前,避免不必要的判断:
```
switch (strcmp(lhdcv5_support, "false")) {
case 0:
if (!isLhdcWhitelist || !btif_av_get_lhdc_codec_state()) {
lhdc_flag = true;
}
break;
default:
if (isLhdcBlacklist || !btif_av_get_lhdc_codec_state()) {
lhdc_flag = true;
}
break;
}
```
3. 将判断条件进行拆分和简化,使代码更加易读:
```
bool isLhdcCodecId = (A2DP_VendorCodecGetCodecId(p_codec_info) == A2DP_LHDCV5_CODEC_ID);
bool isLhdcEnabled = btif_av_get_lhdc_codec_state();
bool isLhdcWhitelistDisabled = !isLhdcWhitelist || !isLhdcEnabled;
bool isLhdcBlacklistEnabled = isLhdcBlacklist || !isLhdcEnabled;
if (isLhdcCodecId) {
switch (strcmp(lhdcv5_support, "false")) {
case 0:
if (isLhdcWhitelistDisabled) {
lhdc_flag = true;
}
break;
default:
if (isLhdcBlacklistEnabled) {
lhdc_flag = true;
}
break;
}
}
```
这样,代码更加简洁、清晰,易于维护。
阅读全文