C特性——持续学习更新

1、attribute

关键字__attribute__也可以对结构体(struct)或共用体(union)进行属性设置。大致有六个参数值可以被设定,即:aligned, packed, transparent_union, unused, deprecated和may_alias。

  1. attribute((deprecated)) 管理过时的代码
    在开发一些库的时候,API的接口可能会过时,为了提醒开发者这个函数已经过时。可以在函数声明时加上attribute((deprecated))属性。这样,只要函数被使用,在 编译是都会产生警告 ,警告信息中包含过时接口的名称及代码中的引用位置。

示例如下:
旧版本代码:

typedef struct {
  float left;
  float top;
  float right;
  float bottom;
  float score;
  float class_label;
} bbox_type_t;

3.7.1新版本,将结构体命名更改:

#define HBRT_DEPRECATED_NAME(new_name, old_name, version_since) \
__attribute__ ((deprecated(#old_name " has been superseded by " #new_name " since " #version_since ", and will be removed in a future release")))

typedef struct {
  float left;
  float top;
  float right;
  float bottom;
  float score;
  float class_label;
} bbox_float_type_t;

typedef bbox_float_type_t bbox_type_t HBRT_DEPRECATED_NAME(bbox_float_type_t , bbox_type_t, 3.7.1);

用typedef 兼容前后版本的使用,再用__attribute__ ((deprecated))的方式声明该命名已经过时,在编译时产生警告。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值