Reputation: 512
I have declared a static variable, and use the static variable in two processes.
Is there only one static variable between processes or each has its own?
I focus on multi processes, not for static variable syntax
Upvotes: 0
Views: 1326
Reputation: 238401
Is there only one static variable ...
Depends on context.
If it is a static member or a static variable in block scope then yes, there is only one instance.
If it is a static variable in namespace scope, then there are as many instances of the variable as there are translation units using the variable.
... between processes or each has its own?
The C++ language has no concept of a process. As such there is no such thing as a variable shared between processes in the language. When I say "only one instance" in the previous part, it effectively means same as "only one instance per process".
Upvotes: 4