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 function question

Status
Not open for further replies.

electroRF

Member
Hi guys,
I have a question please.

Say that you define an Inline Function in an H File.
e.g.
C:
__inline unsigned int returnMax(int a, int b)
{
     if (a > b)
          return a;
      return b;
}

If no one calls this function, will it occupy zero memory?

If the Inline Function was defined as Static Inline, e.g.:
C:
static __inline unsigned int returnMax(int a, int b)
{
     if (a > b)
          return a;
      return b;
}

Will it still occupy Zero Memory if no one calls it?

I'm using GNU Compiler.

Thank you.
 
Compiler to compiler!!!!

The first one shouldn't be compiled, dependent on optimization..
The second shouldn't also, dependent on optimization..
Using volatile it will always be compiled..

C:
volatile __inline unsigned int returnMax(int a, int b)
{
     if (a > b)
          return a;
      return b;
}
 
Thank you folks!

NG
What do you mean please by ignore it?

Inline tells the compiler to "copy paste" the function's code to where the Caller calls it.
 
You need to get to grips with YOUR compiler.... Try writing a section of code... Use variables and functions that are/ aren't used variables that are initialized but unused... Compile with differing levels of optimization and you'll soon see what is compiled and what isn't..
 
What do you mean please by ignore it?

Inline tells the compiler to "copy paste" the function's code to where the Caller calls it.

You give the compiler a hint. Whether it takes it or not is up to the compiler.

BTW: inlining is more compilcated than copy/paste.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top