(void)(&x==&y)


#define min(x,y) ({ \
        typeof(x) _x = (x);        \
        typeof(y) _y = (y);        \
        (void) (&_x == &_y);                \
        _x < _y ? _x : _y; })

...


写这个宏的人考虑了如下几个问题:
1、如何避免带参宏的副作用。
2、如果两个入参类型不同,作者不能保证在这种情况下得到预期的比较结果,于是以一种编译器能够识别的方式“制造”出警告信息。类似于#error的用法。
3、通过void显式丢弃一个表达式的值,否则有些编译器会就此给出警告信息。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include<iostream> # include <windows.h> # include <stdlib.h> using namespace std; int main() { fighter f; f.drawPicture(); } class fighter{ public: int height = 40, width = 20; //游戏画面尺寸 int fighter_x = height / 2, fighter_y = width / 2; //飞机位置 int bullet_x, bullet_y; //子弹位置 int life = 3, mark = 0;//生命值和分数 int enemy_x = rand() % (width - 5) + 2, enemy_y = 1;//敌机位置 //fighter(int fighter_x, int fighter_y); void HideCursor() { CONSOLE_CURSOR_INFO cursor_info = { 1,0 }; //第二个值为О表示隐藏光标 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } void zeroXy(int x, int y) { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(handle, pos); } void floatBullet() { } void drawPicture() { zeroXy(0, 0); cout << "生命值:" << life << " " << "分数:" << mark << endl;; for (int y = 0; y <= width; y++) { for (int x = 0; x <= height; x++) { if (y == 0 || y == width) { cout << "*"; } else if (x == 0 || x == height) { cout << "*"; } else if (x == fighter_x && y == fighter_y || y == fighter_y - 1 && x == fighter_x || y == fighter_y - 2 && x == fighter_x || x == fighter_x + 1 && y == fighter_y || x == fighter_x - 1 && y == fighter_y) { cout << "+";//飞机 } else if (x == enemy_x && y == enemy_y) { cout << "#";//敌机 } else if (x == bullet_x && y == bullet_y) { cout << "|"; } else { cout << " "; }//画出范围 } cout << endl; } } };如何优化
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值