Heeryu
Heeryu

Reputation: 872

Function pointer for inline function C

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?

Upvotes: 3

Views: 979

Answers (2)

ryyker
ryyker

Reputation: 23218

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

Upvotes: 2

disco beat
disco beat

Reputation: 188

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

Upvotes: 3

Related Questions