The standard says that:
When a name has an internal connection, the object that it designates may be referenced by names from other areas in the same translation unit.
and
A name that has a namespace scope (3.3.6) has an internal relationship if it is a name for a variable, function, or function template that is explicitly declared static;
So, consider the following code:
#include <stdio.h> namespace A { /* a with internal linkage now. Entity denoted by a will be referenced from another scope. This will be main() function scope in my case */ static int a=5; } int main() { int a; //declaring a for unqualified name lookup rules printf("%d\n",a);//-1216872448 }
I really don't understand the definition in the standard. What does it mean:
the object that it denotes can be called by names from other areas in the same translation unit.
A #include d .
#include
A name , , ( ). static, , , .
static
a, a, name a main . main a, a a. a , a, main. a a main, cout<<A::a using namespace A; , main.
a
main
cout<<A::a
using namespace A;
" " - , . .cpp , .
.cpp
, . ; "" , . "" , .
, printf, ( ) printf . 1), printf , 2), , , 1) 2).
printf
printf - ; , . , - . , main A::a, static , , , A::a. , A::a .
A::a
, , , a, main , , , . . main :
int main() { printf("%d\n", A::a); }
5.
5
, , .
, .
a. a, A. , , , .
static int a = 5; // a new entity with name `a` that has internal linkage. int main() { int a; // This is a new entity local to function main with no linkage. // It isn't initialized, so you have undefined behavior if you try to // access it. }
, a, , .
, , :
static int a = 5; // A new entity with the name `a` that has internal linkage. void f() { extern int a; // This is a new declaration for the same entity called `a` in // the global scope. }
, . .
. f() f(), , , f a , . , a static, a .
f()
Source: https://habr.com/ru/post/1540461/More articles:What is the reason for cloning an object in java? - javaPython Rope: how to find all missing import and errors in all refactoring of all modules - pythonGitHub Push Automation on VSOnline - gitHow to define global variables in slim framework - phpProguard, the class of the library depends on the class of the program - androidWhat do DECLSPEC and SDLCALL mean in function definitions in the Linux header file? - cКонструктор Comparer - c#Entity Framework: Why is a property of type of an array of objects not stored in the database? - ormHow can I accept input in several languages in android - androidPython how to override a method defined in a third-party library module - pythonAll Articles