Will a function declared inside main() have external linkage or none linkage?

See the following code:

/* first file */

int i; /* definition */
int main () {
  void f_in_other_place (void);   /* declaration */
  i = 0
  return 0;
}
/* end of first file */


/* start of second file */

extern int i; /* declaration */
void f_in_other_place (void){   /* definition */
  i++;
}
/* end of second file */

I know that external objects have external linkage and internal objects have none linkage(ignoring extern for a moment). Now if i talk about the function f_in_other_place(), it is declared inside main function. So will the identifier for it be treated as an internal object ? If yes than it should have none linkage but as visible in program this function refers to it's definition in second file which shows that identifier for it is behaving like an object with external linkage. So i am confused whether this identifier here has external linkage or none linkage ?

Now coming to the extern keyword, I read somewhere that function declaration implicitly prefixes extern. So even if i have not mentioned extern for this function identifier explicitly, will my function's identifier by default become an object with external linkage and scoped inside main() ? Please correct me if i am going in wrong direction.



Read more here: https://stackoverflow.com/questions/64388332/will-a-function-declared-inside-main-have-external-linkage-or-none-linkage

Content Attribution

This content was originally published by LocalHost at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: