3
inline void myfunction(){
    //something here
}

void main(){
    void (*p)(void);
    p = myfunction;
    p();
}

What kind of machine code different compilers can generate for this, and in what situations?

5
  • 4
    Your compiler will certainly make the function non inline but it may also create two verions of the function, one inline and one non inline, all depends on your compiler. Commented Feb 11, 2014 at 15:07
  • 1
    @MichałWalenciak I only have gcc on my machine and I asked about other compilers too. Commented Feb 11, 2014 at 15:18
  • 2
    @MichałWalenciak: Testing would only tell you whether the C implementation you use permits it. Since that could be an implementation-specific extension to C, it would not tell you whether it is defined by the C standard. Commented Feb 11, 2014 at 15:27
  • @EricPostpischil how to test whether the function call is inlined or not? Commented Feb 11, 2014 at 16:26
  • @ajay you can compile with -S flag to generate assembly code. Commented Feb 11, 2014 at 16:29

2 Answers 2

3

As your compiler will need the adress of the function, it will generate a stand alone copy of the object code.

Sign up to request clarification or add additional context in comments.

1 Comment

It may also generate inline copies of the function in this source file if the function is used in other places in the file.
2

Yes - but it will depend on your compiler and its settings what side effects will occur:

There are various ways to define inline functions; any given kind of definition might definitely emit stand-alone object code, definitely not emit stand-alone object code, or only emit stand-alone object code if it is known to be needed. Sometimes this can lead to duplication of object code...

From Here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.