MISRA 2012规则8.10静态内联 [英] MISRA 2012 rule 8.10 static inline

查看:90
本文介绍了MISRA 2012规则8.10静态内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么MISRA建议使用静态存储类声明内联函数?尽管关键字inline提示编译器将所有函数调用替换为实际的函数主体,并且编译器可能会执行或可能不会执行该调用,但是给函数提供内部链接(静态)或外部链接(extern)会如何通过以下方式影响内联操作:编译器?

Why does MISRA recommends a inline function to be declared with static storage class? While the keyword inline is a hint to compiler to replace all function calls with actual function body and compiler may or may not perform it, how does giving a internal linkage (static) or external linkage (extern) to a function affect the inline operation by the compiler?

推荐答案

MISRA C:2012给出了规则8.10的基本原理:

MISRA C:2012 gives the rationale for rule 8.10 as:

理性

如果内联函数是使用外部链接声明的,但未在同一转换单元中定义,则该行为是未定义的.

If an inline function is declared with external linkage but not defined in the same translation unit, the behaviour is undefined.

对通过外部链接声明的内联函数的调用可能会调用 函数的外部定义,也可以使用内联 定义.虽然这不应该影响 称为函数,它可能会影响执行时间,因此具有 对实时程序的影响.

A call to an inline function declared with external linkage may call the external definition of the function, or it may use the inline definition. Although this should not affect the behaviour of the called function, it might affect execution timing and therefore have an impact on a real-time program.

这篇关于MISRA 2012规则8.10静态内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆