【问题标题】:C programming: How to deprecate INLINE functionC 编程:如何弃用 INLINE 函数
【发布时间】:2021-12-03 20:44:51
【问题描述】:

如何弃用__STATIC_INLINE 函数。我知道我必须使用__attribute__ ((deprecated)) 但如何将其用于以下功能:

__STATIC_INLINE void Foo()
{
  ...
}

更新: 我的目标是使用 #define 声明弃用属性,例如: #define THIS_IS_DEPRECATED __attribute__ ((deprecated))

并使用 #define 弃用 API。

更新 2:如果我使用,建议的解决方案工作 50%:

__STATIC_INLINE void THIS_IS_DEPRECATED Foo()
{
  ...
}

现在我收到了弃用警告,但出现了另一个错误:

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Foo'
  428 | __STATIC_INLINE void THIS_IS_DEPRECATED Foo(void)
      |                                         ^~~~~~~~~

【问题讨论】:

  • __attribute__ ((deprecated)) __STATIC_INLINE void Foo() 不工作吗?
  • No :( 不行,我觉得属性应该在最后。
  • want to use the attribute within a #define like: #define THIS_IS_DEPRECATED __attribute__((deprecated)) and use the #define instead.所以用它,你问这里干嘛?

标签: c deprecated


【解决方案1】:
static inline __attribute__((deprecated)) void Foo()
{
  
}

为我工作。当我尝试使用它时它会生成一个警告。

但是我不确定__STATIC_INLINE 是什么?

根据您的评论进行编辑:

你的意思是像

#define THIS_IS_DEPRECATED __attribute__((deprecated))

static inline THIS_IS_DEPRECATED void Foo()
{
  
}

【讨论】:

  • 是的,确实有效,但我认为我没有发布整个问题。实际上我想在#define 中使用该属性,例如:#define THIS_IS_DEPRECATED __attribute__((deprecated)) 并改用#define。我刚刚更新了帖子
  • 我认为您问题中的编辑应该有效?
  • not sure what the __STATIC_INLINE is? 可以是任何东西,但在 ARM CMSIS 库中可以使用相同的宏:github.com/mikeferguson/stm32/blob/master/libraries/CMSIS/…。 ||无论如何,将属性放在返回类型和函数名之间很奇怪,我会把它放在前面。 static inline __attribute__((__deprecated__)) rettype function();。还有gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
  • @KamilCuk 我同意,这样会更好,我会编辑我的遮阳篷
  • 可行,但现在我收到另一个错误error: expected ';' before 'void' 415 | __STATIC_INLINE THIS_IS_DEPRECATED void Foo(bool enable)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多