The linker is reporting multiply defined errors for an inline function.
I have the following code in a header file:
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;
}
I include the header file in more than one source (.c) file.
I would like to have the above function pasted inline wherever it is called.
Is there a technique for this without have multiple definitions of the function in each source file that is included? If yes, please provide example.
I need the performance optimization for an embedded platform.
Are compilers or linkers smart enough to inline functions when they are defined in other translation units?
I am using Green Hills compiler, 4.2.4 on an embedded ARM9 platform. Assume pre-2000 C language standard. This is C code not C++.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…