On 16 Ott, 12:09, Ian Collins <ian-n...@hotmail.com> wrote:
> On 10/16/11 09:16 PM, pozz wrote:
> > I tried, the linker I'm using can't. *Also the compiler (even with
> > optimization) doesn't transform normal functions to inline functions,
> > without the inline keyword.
>
> So use it! *At least the compiler honours the hint. *Embedded compilers
> tend to offer more control over what is and isn't inlined than their
> hosted brethren.
Unfortunately, I have another "warning" problem if I use inline
functions.
Suppose I have a macro that activate a relay connected to a
microcontroller pin:
#define RELAY_ON() do {PIN_SET_OUTPUT(10); PIN_SET(PIN(10));}
while(0)
The first instruction is to configure the pin as an output; the second
is to set its level to high.
Transforming this macro to an inline function, I would write:
#pragma inline relay_on
void relay_on(void) {
PIN_SET_OUTPUT(10);
PIN_SET(PIN(10));
}
If this function is accessible just from one compilation module, it is
simple to use it:
-- test.c --
#include "cpu.h"
#pragma inline relay_on
static void relay_on(void) {
PIN_SET_OUTPUT(10);
PIN_SET(PIN(10));
}
void test(void) {
relay_on();
/* other things */
}
-- test.h --
#ifndef TEST_H
#define TEST_H
#include "test.h"
void test(void);
#endif
--
The compilation ends without any errors and warnings.
The problem happens when I try to use this function in more than one
module,
so moving the code to include file (I think this is the way to have an
extern
inline function):
-- test.h --
#ifndef TEST_H
#define TEST_H
#pragma inline relay_on
void relay_on(void) {
PIN_SET_OUTPUT(10);
PIN_SET(PIN(10));
}
#endif
--
If I include test.h in more than one file, the compilation ends with
the warning
W1327L: Duplicate symbol definition (_relay_on)
even if the function relay_on() is never used. So the use of inline
function to
avoid a warning has produced another warning