【问题标题】:What does the __attribute__((force)) do?__attribute__((force)) 有什么作用?
【发布时间】:2018-11-02 14:38:24
【问题描述】:

这听起来像是我应该可以在 Google 上搜索到的内容,但我找不到很好的参考。 __attribute__((force)) 到底是做什么的?如:

 return (__attribute__((force)) uint32_t) *p

(这是一个 ARM 系统,用 clang 交叉编译,但我在这个属性的任何地方都找不到任何引用,即使在 clang/arm 特定页面中也是如此..)。

【问题讨论】:

  • 甚至没有提到here...
  • 顺便问一下p 是什么? uint32_t*?
  • 可能是某个特定端口中的某个本地#define?我猜这与对齐有关。
  • 您是否尝试过预处理您的代码以查看 force 是否不是宏?
  • 看起来它与名为 sparse 的东西一起使用。

标签: c attributes arm clang


【解决方案1】:

__attribute__((force)) 用于抑制 sparse 中的警告,这是 linux 内核的 c 语义检查器。

wikipedia article of sparse 列出了 sparse 定义的以下属性:

  • address_space(num)
  • 按位
  • 强制
  • 上下文(表达式,in_context,out_context)

如果您需要有关这些的更多信息,可以查看the man page of sparse

在 linux 内核中,一些这些属性在 linux/include/linux/compiler_types.h 中重新定义。例如,__force 扩展为 __attribute__((force))__bitwise 扩展为 __attribute__((bitwise))

但是linux documentation about sparse 告诉我们,gcc 忽略了这些属性:

使用 gcc,所有“__bitwise”/“__force 的东西”都消失了,最终看起来就像 gcc 的整数。

【讨论】:

    猜你喜欢
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多