Can multiple files have functions with the same name and signature? Is it possible to use a global variable defined in another file in the file? Is it possible to define a variable in the nested block with the same identifier as the variable in the outer block? How to limit the scope of a global variable to a single file? Can a variable in an application be declared exclusively with an extern memory class?
Closed due to the fact that the question is too common for participants Vlad from Moscow , vp_arth , αλεχολυτ , Harry , Kromster Mar 1 '17 at 5:16 .
Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Most of these questions are meaningless, self-contradictory terminology porridge. What is a "have function"? Have ads? Or definitions? "It is impossible to restrict the use of a global variable by one file", because then this variable will no longer be global. "Exceptional with extern memory class"? Any variable always has only one memory class. There is no other way. What is the meaning of the mention of "exclusivity"? - AnT
- @Zolberg N You have already asked a similar question. Why do you replicate the questions? - Vlad from Moscow
- Possible duplicate question: Variables (help) - vp_arth
- "With the same name and signature" - but in C ++ the name is already included in the signature. What then is "with the name AND signature"? And in C there is no concept of a function signature. - AnT
1 answer
Can multiple files have functions with the same name and signature? If both files are in the same application - no.
Is it possible to use a global variable defined in another file in the file? Can. See external attribute
Is it possible to define a variable in the nested block with the same identifier as the variable in the outer block? Can.
How to limit the scope of a global variable to a single file? See the static attribute
Can a variable in an application be declared exclusively with an extern memory class? What does "exclusively" mean? In general, it can. For example:
extern int errno; - 2Regarding the first question: it seems that if we declare such functions with the static modifier, everything will work, each such function will be "limited" by its translation unit. - isnullxbh
- Yes, of course you are right! - Sergey