リンカは、インライン関数に対して複数定義されたエラーを報告しています。
ヘッダーファイルに次のコードがあります。
struct Port_Pin
{
volatile uint32_t * port_addr_set_value; //!< Writing the pin value here sets the pin to high.
volatile uint32_t * port_addr_clr_value; //!< Writing the pin value to this port clears the pin to low.
volatile uint32_t * port_addr_read_value; //!< Address to read pin value.
volatile uint32_t * port_addr_enable; //!< Writing the pin value here enables the pin (for reading or writing).
volatile uint32_t * port_addr_disable; //!< Writing the pin value here disables the pin.
volatile uint32_t * port_addr_dir_output; //!< Writing the pin value here sets the pin as an output.
volatile uint32_t * port_addr_dir_input; //!< Writing the pin value here sets the pin as an input.
unsigned int pin_bit_position; //!< Zero based, where position zero is first bit position.
};
inline void
Write_Port_Pin(const struct Port_Pin * p_port,
uint8_t bit)
{
volatile uint32_t * port_addr = 0;
port_addr = ((bit & 1) == 0) ? p_port->port_addr_clr_value
: p_port->port_addr_set_value;
*port_addr = 1 << p_port->pin_bit_position;
return;
}
ヘッダーファイルを複数のソース(.c)ファイルにインクルードします。
上記の関数は、どこで呼び出されてもインラインで貼り付けてもらいたいです。
含まれている各ソースファイルに関数の複数の定義がない場合のこのための手法はありますか? はいの場合、例を挙げてください。
組み込みプラットフォームのパフォーマンスを最適化する必要があります。
コンパイラまたはリンカは、他の変換単位で定義されている場合に関数をインライン化するのに十分スマートですか?
組み込みARM9プラットフォームでGreenHillsコンパイラ4.2.4を使用しています。2000より前のC言語標準を想定します。これはC++ではなくCコードです。