最近在看Atmel官方庫文件時,發現在他的.h頭文件中,有大量static inline這樣的方式定義函數,有幾個疑問,
1,不是說不能在頭文件中定義函數嗎,只能聲明嗎?為什么能用這種方式在頭文件中定義函數
2,函數前加上static不是表示靜態嗎,為什么這些函數我還能在其他源文件中引用呢?
3,官方static inline這樣定義有什么好處?
大概是如下這種形式:
#ifndef ATMEL_START_PINS_H_INCLUDED
#define ATMEL_START_PINS_H_INCLUDED
#include <port.h>
static inline void sum_set_pull_mode(const enum port_pull_mode pull_mode)
{
PORTB_set_pin_pull_mode(0, pull_mode);
}
static inline void sum_set_dir(const enum port_dir dir)
{
PORTB_set_pin_dir(0, dir);
}
|