|
|
View previous topic :: View next topic |
Author |
Message |
championx
Joined: 28 Feb 2006 Posts: 151
|
Inline Functions |
Posted: Tue May 12, 2015 5:49 am |
|
|
Hi! is there a list of all of the "inline" functions?
I'm having trouble to make my code enter on a pic. Recently i discovered that the read_eeprom and write_eeprom are functions that the compiler write inline, so then i make another function that called write_eeprom and read_eeprom and that make the code a lot smaller.
Is there other functions that are coded inline by the compiler?
thanks! |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Tue May 12, 2015 9:48 am |
|
|
Any of the compiler functions that don't require a header file to use (most of them) are going to be "built in", which is different than "inline". If you look at the .h file for your PIC, you'll see them either mentioned in the comments (v4 compilers) or actually forward declared with _bif in front of them (v5 compiler). Aside from that, the manual lists all the functions the compiler has as well. |
|
|
championx
Joined: 28 Feb 2006 Posts: 151
|
|
Posted: Tue May 12, 2015 9:59 am |
|
|
Hi jeremiah, thanks for your answer. Sorry, i think I'm not writing clearly enough. (english is not my native language).
When i talk about "inline" functions I'm talking about that functions that the compiler copies the code every time that you use them, like write_eeprom.
If you do this:
Code: | write_eeprom(A,B);
write_eeprom(A,B);
write_eeprom(A,B);
write_eeprom(A,B); |
It consumes a lot of ROM.
But if you do this:
Code: | write_config(int address, int value)
{
write_eeprom(address, value);
}
write_config(A,B);
write_config(A,B);
write_config(A,B);
write_config(A,B); |
it consumes much more LESS rom.
So my question is: Are there another built-in functions that act as "inline" functions when you call them?
thanks! |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Tue May 12, 2015 1:54 pm |
|
|
In general the compiler chooses to make a function inline or not based on the context of the program you write and the chip you are writing it for. Not all functions are always inline and even those that typically are aren't "always" inline. output_low(PIN_B13) for example will always generate inline code, but change PIN_B13 to a variable and the nature of the function changes and may not be inline.
What chip are you using and what compiler version?
Here is a quick test example for the PIC24FV32KA304. It doesn't generate any inline code for write_eeprom using the 5.044 version compiler
Code: |
#case
#include <24FV32KA304.h>
void write_config(int8 address, int8 value){
write_eeprom(address,value);
}
void main()
{
unsigned int8 addr = 10;
unsigned int8 val = 10;
write_eeprom(0,0);
write_eeprom(2,2);
write_eeprom(4,4);
write_eeprom(addr,val);
write_config(addr,val);
while(TRUE);
}
|
If you switch this example to use your chip does it generate inline code, and if so, can you post an example of the LST file that shows that? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Wed May 13, 2015 2:08 am |
|
|
It also changes it's decision, when the memory gets close to full.
An inline function, uses more ROM, but less scratch RAM, and is slightly faster. When there is plenty of ROM, the compiler will inline things 'by default'. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|