Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

#inline and #separate directives

Status
Not open for further replies.

3v0

Coop Build Coordinator
Forum Supporter
This is not about inline assembly code.

The CCS compiler allows the use of #inline just prior to a function.
This instructs the complier to put a copy of the code inline each time the function is "called". For that reason no call happens.

Has anyone seen a similar directive on other PIC C compilers. I have not see where C18 has one.
 
Not that I know of. It does do the opposite with procedural abstraction. I guess the closest thing to the #inline function would be a macro.
 
Last edited:
I know the op reffered to C compilers, but the post did spark a thought from the **broken link removed**help file I was reading not long ago;

Code:
Inline
  

When an inline subroutine or function is generated, the computational expense of a call and return is removed by inserting the subroutine or function statement block at the point where the original call was made. By default, the compiler will make all subroutines and functions inline, if they are called only once from your program. For example, the following Print() subroutine
 

sub Print()

   USART.Write("Hello World", 13, 10)

end sub

SetBaudrate(br19200)

Print

USART.Write("The End", 13, 10)

 

would be converted to inline, which is the same as writing,

 

SetBaudrate(br19200)

USART.Write("Hello World", 13, 10)

USART.Write("The End", 13, 10)

 

You can force the compiler to always inline a subroutine or function by 

prefixing the declaration with the inline keyword. For example,

 

inline sub Print()

   USART.Write("Hello World", 13, 10)

end sub

 

To prevent the compiler from making a subroutine or function inline, simply prefix the declaration with the noinline keyword. For example,

 

noinline sub Print()

   USART.Write("Hello World", 13, 10)

end sub

 

Take care when explicitly making a subroutine or function inline. Although inline routines remove the time overhead associated with making a call, there can be a significant cost in terms of code space used. Generally, you should only use inline for very small routines that need to execute quickly.
 
gramo said:
I know the op reffered to C compilers, but the post did spark a thought from the **broken link removed**help file I was reading not long ago;
SF seems to be quite the compiler. From the code section you posted.
When an inline subroutine or function is generated, the computational expense of a call and return is removed by inserting the subroutine or function statement block at the point where the original call was made. By default, the compiler will make all subroutines and functions inline, if they are called only once from your program. For example, the following Print() subroutine

I am suprised not to find it in C18. It does not exist in the documentation and and a function with a single call did not create one. I did not change my command line switches and it was the student version. Maybe in the full version.

Wikipedia has more info if anyone wants to learn more about inline functions or why they they should be used instead of macros.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top