jbulatek
jbulatek

Reputation: 164

Inline function global scope

As I read here inline functions doesn't have to be inlined. So let's say we have code like this:

int a = 0;

inline void myFunc(){
    extern int a;
    a = 1;
}

int main(){
    int a = 0;
    myFunc();
}
  1. Does standard guarantee which a variable will be assigned 1?
  2. Are inline function compiled to a certain code before inlining? If so, what if I use register keyword for a in main?

EDIT: the global int a doesn't have to be declared in the same .c file

Upvotes: 0

Views: 231

Answers (1)

rici
rici

Reputation: 241701

Inlining a function does not introduce it into the caller's scope. Identifiers declared within a function (such as a in main in your example) are not visible from other functions.

So inline is irrelevant, and the top-level a is the one whose value is changed.

Upvotes: 1

Related Questions