#pragma INLINE

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

#pragma INLINE

跳至解决方案
2,990 次查看
jag
Contributor IV

Hello, I'm using CW 6.2 on a HS08QE16.

 

I've a function in foo.c:

 

#pragma INLINE

void bar(void)

{

      //do something short 

 

Compiler has the -Oi flag. 

 

Now, if' I call this function within foo.c, it's inlined.

But if I use it on another file (for example main.c) it's not inlined. And I wish that it will be inlined everywhere.

In foo.h there is simply the declaration:

void bar(void);

 

I tried using extern:

extern void bar(void);

but it doesn't change anything.

 

Some ideas?

 

Thanks Bye Jack 

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,358 次查看
BlackNight
NXP Employee
NXP Employee

Hello,

the compiler will only inline functions he is able to 'see': if the function is inside the same file, and above where you want to inline it.

So it is a good idea to place the functions to be inlined at the beginning of the C file.

If your function 'bar' does something short, you may consider to make a C macro out of it and have it placed in a header file: that way you can get inlining through the preprocessor.

The other idea would be to have bar() in a separate small file (defined as static function, btw):

Then you could include this file in each of the modules where you want to inline it.

In order not to change a lot of files (to include this 'inline' file), you could simply use the -AddIncl command line switch (e.g. -AddInclMyIncludeFile.inc )

 

BK

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,359 次查看
BlackNight
NXP Employee
NXP Employee

Hello,

the compiler will only inline functions he is able to 'see': if the function is inside the same file, and above where you want to inline it.

So it is a good idea to place the functions to be inlined at the beginning of the C file.

If your function 'bar' does something short, you may consider to make a C macro out of it and have it placed in a header file: that way you can get inlining through the preprocessor.

The other idea would be to have bar() in a separate small file (defined as static function, btw):

Then you could include this file in each of the modules where you want to inline it.

In order not to change a lot of files (to include this 'inline' file), you could simply use the -AddIncl command line switch (e.g. -AddInclMyIncludeFile.inc )

 

BK

0 项奖励
回复