T
TTroy
I have a few questions about "scope" and "visibility," which seem like
two different things.
To me "visibility" of the name of a function or object is the actual
code that can use it in an actual program.
To me "scope" of the name of a function or object are the general rules
for the areas of a program that can through a declaration, have
"visibility."
[By "to me," I'm stating that this is how I use the terms.]
Ex:
Externally defined variables have global scope <- Scope rule
The variable int i; in main.c has visibility in both main.c and test.c
because there are declarations at the top of both files. <- describing
visibility
So it's as if, there are two steps to being able to access a function
name or object name - first the code must fall in the scope of the said
name, second the code must be in the visibility area of the said name
(via a declaration).
Am I right? Scope can be determined when an object or function is
defined, visibility can only be determined via declarations. If I'm
not right, then which two terms differentiate the ACTUAL VISIBILTY AREA
from the TOTAL POSSIBLE VISIBILITY AREA?
Also, say I have 2 source files main.c and second.c, and there is an
external variable defined at the top of main.c.
I only want to use this variable in 1 function in second.c, can I put
the extern declaration inside the function's braces (will this limit
others in second.c from accessing the variable?) ?
If the answer above is yes, then that is a better example of what I was
saying above. The scope would be all code in both files, while the
visibility would be all of main.c and just that function in second.c.
I haven't found enlightenment in any of the books or FAQs I've checked,
so any help would be really appreciated.
two different things.
To me "visibility" of the name of a function or object is the actual
code that can use it in an actual program.
To me "scope" of the name of a function or object are the general rules
for the areas of a program that can through a declaration, have
"visibility."
[By "to me," I'm stating that this is how I use the terms.]
Ex:
Externally defined variables have global scope <- Scope rule
The variable int i; in main.c has visibility in both main.c and test.c
because there are declarations at the top of both files. <- describing
visibility
So it's as if, there are two steps to being able to access a function
name or object name - first the code must fall in the scope of the said
name, second the code must be in the visibility area of the said name
(via a declaration).
Am I right? Scope can be determined when an object or function is
defined, visibility can only be determined via declarations. If I'm
not right, then which two terms differentiate the ACTUAL VISIBILTY AREA
from the TOTAL POSSIBLE VISIBILITY AREA?
Also, say I have 2 source files main.c and second.c, and there is an
external variable defined at the top of main.c.
I only want to use this variable in 1 function in second.c, can I put
the extern declaration inside the function's braces (will this limit
others in second.c from accessing the variable?) ?
If the answer above is yes, then that is a better example of what I was
saying above. The scope would be all code in both files, while the
visibility would be all of main.c and just that function in second.c.
I haven't found enlightenment in any of the books or FAQs I've checked,
so any help would be really appreciated.