This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / Jabber's Q(3)I have another stupid question. Suppose I have a variable defined at the very beginning of a .cpp file. If I put a modifer
"static" before its declarion, will its scope be wider or narrower?
-jabber(jabber);
2000-9-14
{194}
(#8616@0)
-
it's a C language concept than C++
-guest:zack;
2000-11-3
{588}
(#13101@0)
-
The correct answer is ...The correct answer is that the scope of that variable do not change.
Its scope remains file scope. Zack's answer confused concept of "scope" with concept of "linkage", and concept of "local duration" with concept of "dynamic duration" in C++ language.
-old(HH);
2000-11-11
{262}
(#14029@0)
-
Probably both Zack and you are rightHuman languges have great ambiguities. For the same words, people may have different understandings.
Indeed, the global variables are still available in the file in which they are defined, after a "static" key word is applied.
However, they are no longer available in other C++ source files even we claim they are "extern".
Such things sounds trivial to C++ veterans, but not all C++ gurus can explain them elegantly. Thank you for discussions.
-jabber(jabber);
2000-11-12
{464}
(#14214@0)
-
Thank you for your commnets. To discuss more precisely ...Thank you for your commnets.
To discuss more precisely.
The scope of a global variable will not change after a "static" key word is applied. But its linkage changes from external to internal after a "static" key word is applied. Scope and linkage are closely related but different concepts in C++.
I think that a programmer should make efforts to pay attention to details and think precisely.
-old(HH);
2000-11-12
{400}
(#14245@0)
-
Philosophically, I second to you.
-jabber(jabber);
2000-11-14
{775}
(#14441@0)
-
It is sure, as you said, that human lanaguges have intrinsic ambiguities.It is sure, as you said, that human lanaguges have intrinsic ambiguities.
However, I am sorry to say, I don't think that is my own explanation. I am not capable of explaining such thing myself. I think it probably is a specification of C/C++.
I just try to make things clear.
I wrote in English because these discussions did not matter very much and provided opportunities for me to practise my terrible English.
Thank you.
-old(HH);
2000-11-15
{430}
(#14606@0)