当前位置: 首页 > news >正文

欧美化妆品网站模板下载网站建设找哪家好

欧美化妆品网站模板下载,网站建设找哪家好,免费注册发布信息网站,2024最火的十大新闻有哪些文章目录 编译时校验功能描述代码实现示例代码正常编译示例编译错误示例预处理之后的结果 代码解析!!estruct {int:-!!(e); }sizeof(struct {int:-!!(e); }) 参考代码 编译时校验 功能描述 用于在编译时检查一个条件是否为真,如果条件为真则会编译失败&#xff0c…

文章目录

  • 编译时校验
    • 功能描述
    • 代码实现
    • 示例代码
      • 正常编译示例
      • 编译错误示例
      • 预处理之后的结果
    • 代码解析
      • `!!e`
      • `struct {int:-!!(e); }`
      • `sizeof(struct {int:-!!(e); })`
    • 参考代码

编译时校验

功能描述

用于在编译时检查一个条件是否为真,如果条件为真则会编译失败,编译器报错

反之如果条件为假,则编译正常,且有返回值,返回 0。

代码实现

/** Force a compilation error if condition is true, but also produce a* result (of value 0 and type int), so the expression can be used* e.g. in a structure initializer (or where-ever else comma expressions* aren't permitted).*/
#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))

参数 e 表示用于判断的表达式

示例代码

正常编译示例

#include <stdio.h>#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))int main(void)
{printf("Compilation successful %d.\n", BUILD_BUG_ON_ZERO(0));return 0;
}

结果打印

Compilation successful 0.

编译错误示例

#include <stdio.h>#define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))int main(void)
{printf("Compilation successful %d.\n", BUILD_BUG_ON_ZERO(1));return 0;
}

编译错误信息

test.c: In function ‘main’:
test.c:3:51: error: negative width in bit-field ‘<anonymous>3 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))|                                                   ^
test.c:7:44: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’7 |     printf("Compilation successful %d.\n", BUILD_BUG_ON_ZERO(1));

预处理之后的结果

gcc -E test.c -> test.i
int main(void)
{printf("Compilation successful %d.\n", ((int)(sizeof(struct { int:(-!!(1)); }))));return 0;
}

代码解析

!!e

对条件 e 进行两次逻辑非运算,得到 逻辑值 结果 0 或者 1。如果表达式 e 的结果为 0 ,则得到 0 , 如果为非 0 值,则得到 1 。

struct {int:-!!(e); }

如果表达式 e 的结果为 0,则得到结构体 struct {int:0;},这是一个匿名的位域结构体,位域宽度为 0。

如果表达式 e 的结果为 1,则得到结构体 struct {int:-1;},则编译错误。由于位域的宽度不能是负的,所以编译错误,提示错误 error: negative width in bit-field <anonymous>

sizeof(struct {int:-!!(e); })

如果表达式 e 的结果为 0,则使用 sizeof 运算符计算得到这个匿名结构体 struct {int:0;} 的大小为 0,宏的返回值为 0。

参考代码

  • https://blog.csdn.net/u012028275/article/details/127478561
http://www.ds6.com.cn/news/72089.html

相关文章:

  • 网站关键词连接符seo优化网站优化排名
  • 风水网站模板比百度好用的搜索软件
  • 网站引流是什么意思日本搜索引擎
  • 有域名了网站怎么做媒体网站
  • 网站后台是什么意思公司官网制作开发
  • 合理规划网站怎么免费建个人网站
  • 印度做网站设计网址怎么弄
  • 网上做批发的网站有哪些下列关于友情链接说法正确的是
  • 最出名的网站建设公司促销式软文案例
  • 简搜网站提交网络服务
  • 自助式网站制作冯耀宗seo
  • 赣州有没有做网站的青岛网站建设方案
  • 扬州网站建设yzbosi网站百度收录批量查询
  • 选择一个网站进行优化福州整站优化
  • 网络营销推广手段seo排名哪家正规
  • 网站建设属于什么职能今日国际新闻最新消息十条
  • 做代购的购物网站seo站内优化站外优化
  • 专门做销售培训的网站网店运营实训报告
  • 潍坊 网站建设常见的营销型网站
  • 广州网站注销备案中国500强最新排名
  • 网络钟点工成都关键词优化报价
  • 做网站的论坛百度爱采购官网首页
  • 建设网站的要求最新新闻头条
  • 沧州哪里做网站爱站网怎么使用
  • 甘肃网站制作公司优化营商环境发言稿
  • 商城网站网站开发seo外链增加
  • 怎么查看网站是否做静态化处理百度账号登录
  • WordPress高级微信机器人网站排名优化培训电话
  • 天津建设工程信息网几点更新北京seo结算
  • 免费网站免费在线观看对网站进行seo优化