Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline functions with internal linkage?

In C: Why is so that only inline functions with internal linkage (ie declared with static) may reference (ie copy address, read, write, or call) a variable or function at file scope with static storage duration while other inline functions may not?

like image 714
Zolomon Avatar asked Mar 07 '10 21:03

Zolomon


People also ask

What is internal linkage?

Internal linkage refers to everything only in scope of a translation unit. External linkage refers to things that exist beyond a particular translation unit. In other words, accessible through the whole program, which is the combination of all translation units (or object files).

Can the linker inline functions?

The linker can inline small functions in place of a branch instruction to that function. For the linker to be able to do this, the function (without the return instruction) must fit in the four bytes of the branch instruction.

Which keyword is used for internal linkage?

To use internal linkage we have to use which keyword? Explanation: static keyword is used for internal linkage.

What are inline functions explain with example?

Example 1. C++ Copy. // inline_keyword1.cpp // compile with: /c inline int max( int a , int b ) { if( a > b ) return a; return b; } A class's member functions can be declared inline, either by using the inline keyword or by placing the function definition within the class definition.


1 Answers

This is how things are defined.

The inlined function would be inserted in the module where it is called. So, it can't access the private stuff in its module where it is defined.

If the inlined function is only used in that module(internal linkage). Then it is safe to grant it an access to the "private" stuff of that module.

like image 102
Khaled Alshaya Avatar answered Sep 18 '22 12:09

Khaled Alshaya