What does C++ language definition say about the extent of the static keyword?What does the explicit keyword mean?Use 'class' or 'typename' for template parameters?What are the rules about using an underscore in a C++ identifier?When to use static classes in C#The Definitive C++ Book Guide and ListWhat does “static” mean in C?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are static variables considered evil?Why are elementwise additions much faster in separate loops than in a combined loop?The static keyword and its various uses in C++
Is a switch from R to Python worth it?
…down the primrose path
What percentage of campground outlets are GFCI or RCD protected?
Broken bottom bracket?
Did Logical Positivism fail because it simply denied human emotion?
ZFS on Linux: Which mountpoint option when mounting manually per script?
How does Geralt transport his swords?
Awk to get all my regular users in shadow
What are the limitations of the Hendersson-Hasselbalch equation?
How to call made-up data?
Can the Cauchy product of divergent series with itself be convergent?
Would the shaking of an earthquake be visible to somebody in a low-flying aircraft?
How to design an effective polearm-bow hybrid?
In MTG, was there ever a five-color deck that worked well?
What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?
Make lens aperture in Tikz
C# TCP server/client class
Is it uncompelling to continue the story with lower stakes?
What could prevent players from leaving an island?
Is there a way to improve my grade after graduation?
Is it okay to use different fingers every time while playing a song on keyboard? Is it considered a bad practice?
How do the surviving Asgardians get to Earth?
What does "autolyco-sentimental" mean?
Are the related objects in an SOQL query shared?
What does C++ language definition say about the extent of the static keyword?
What does the explicit keyword mean?Use 'class' or 'typename' for template parameters?What are the rules about using an underscore in a C++ identifier?When to use static classes in C#The Definitive C++ Book Guide and ListWhat does “static” mean in C?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are static variables considered evil?Why are elementwise additions much faster in separate loops than in a combined loop?The static keyword and its various uses in C++
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In C++, if I have a class:
class Example
static int s_One, s_Two;
...
;
Does the language clearly define that s_Two
is also static?
In other words, does the static
keyword extent go everywhere the int
goes, or can it be like *
and only apply to one variable?
c++ static language-lawyer extent
add a comment |
In C++, if I have a class:
class Example
static int s_One, s_Two;
...
;
Does the language clearly define that s_Two
is also static?
In other words, does the static
keyword extent go everywhere the int
goes, or can it be like *
and only apply to one variable?
c++ static language-lawyer extent
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
9
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago
add a comment |
In C++, if I have a class:
class Example
static int s_One, s_Two;
...
;
Does the language clearly define that s_Two
is also static?
In other words, does the static
keyword extent go everywhere the int
goes, or can it be like *
and only apply to one variable?
c++ static language-lawyer extent
In C++, if I have a class:
class Example
static int s_One, s_Two;
...
;
Does the language clearly define that s_Two
is also static?
In other words, does the static
keyword extent go everywhere the int
goes, or can it be like *
and only apply to one variable?
c++ static language-lawyer extent
c++ static language-lawyer extent
asked 8 hours ago
WilliamKFWilliamKF
16.2k51 gold badges154 silver badges252 bronze badges
16.2k51 gold badges154 silver badges252 bronze badges
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
9
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago
add a comment |
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
9
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
9
9
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Yes, it applies to every name in that declaration:
[dcl.stc]/1:
[..] At most one storage-class-specifier shall appear in a given decl-specifier-seq [..] The storage-class-specifier applies to the name declared by each init-declarator in the list [..]
add a comment |
According to the C++ 17 Standard (10 Declarations)
2 A simple-declaration or nodeclspec-function-declaration of the form
attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;
And (10.1 Specifiers):
1 The specifiers that can be used in a declaration are
decl-specifier:
storage-class-specifier
...
So in this declaration
static int s_One, s_Two;
the decl-specifier-seq
contains two decl-specifiers
, static
(storage class specifier) and int
. Thus the storage class specifier static
describes the both variables in the init-declarator-list
s_One
and s_Two
.
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
@VladfromMoscow why?
– Henri
8 hours ago
3
@VladfromMoscow How is declaring two separatestatic
int
s invalid syntax?
– Jesper Juhl
8 hours ago
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57362724%2fwhat-does-c-language-definition-say-about-the-extent-of-the-static-keyword%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, it applies to every name in that declaration:
[dcl.stc]/1:
[..] At most one storage-class-specifier shall appear in a given decl-specifier-seq [..] The storage-class-specifier applies to the name declared by each init-declarator in the list [..]
add a comment |
Yes, it applies to every name in that declaration:
[dcl.stc]/1:
[..] At most one storage-class-specifier shall appear in a given decl-specifier-seq [..] The storage-class-specifier applies to the name declared by each init-declarator in the list [..]
add a comment |
Yes, it applies to every name in that declaration:
[dcl.stc]/1:
[..] At most one storage-class-specifier shall appear in a given decl-specifier-seq [..] The storage-class-specifier applies to the name declared by each init-declarator in the list [..]
Yes, it applies to every name in that declaration:
[dcl.stc]/1:
[..] At most one storage-class-specifier shall appear in a given decl-specifier-seq [..] The storage-class-specifier applies to the name declared by each init-declarator in the list [..]
answered 8 hours ago
Lightness Races in OrbitLightness Races in Orbit
310k58 gold badges512 silver badges857 bronze badges
310k58 gold badges512 silver badges857 bronze badges
add a comment |
add a comment |
According to the C++ 17 Standard (10 Declarations)
2 A simple-declaration or nodeclspec-function-declaration of the form
attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;
And (10.1 Specifiers):
1 The specifiers that can be used in a declaration are
decl-specifier:
storage-class-specifier
...
So in this declaration
static int s_One, s_Two;
the decl-specifier-seq
contains two decl-specifiers
, static
(storage class specifier) and int
. Thus the storage class specifier static
describes the both variables in the init-declarator-list
s_One
and s_Two
.
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
@VladfromMoscow why?
– Henri
8 hours ago
3
@VladfromMoscow How is declaring two separatestatic
int
s invalid syntax?
– Jesper Juhl
8 hours ago
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
|
show 3 more comments
According to the C++ 17 Standard (10 Declarations)
2 A simple-declaration or nodeclspec-function-declaration of the form
attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;
And (10.1 Specifiers):
1 The specifiers that can be used in a declaration are
decl-specifier:
storage-class-specifier
...
So in this declaration
static int s_One, s_Two;
the decl-specifier-seq
contains two decl-specifiers
, static
(storage class specifier) and int
. Thus the storage class specifier static
describes the both variables in the init-declarator-list
s_One
and s_Two
.
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
@VladfromMoscow why?
– Henri
8 hours ago
3
@VladfromMoscow How is declaring two separatestatic
int
s invalid syntax?
– Jesper Juhl
8 hours ago
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
|
show 3 more comments
According to the C++ 17 Standard (10 Declarations)
2 A simple-declaration or nodeclspec-function-declaration of the form
attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;
And (10.1 Specifiers):
1 The specifiers that can be used in a declaration are
decl-specifier:
storage-class-specifier
...
So in this declaration
static int s_One, s_Two;
the decl-specifier-seq
contains two decl-specifiers
, static
(storage class specifier) and int
. Thus the storage class specifier static
describes the both variables in the init-declarator-list
s_One
and s_Two
.
According to the C++ 17 Standard (10 Declarations)
2 A simple-declaration or nodeclspec-function-declaration of the form
attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;
And (10.1 Specifiers):
1 The specifiers that can be used in a declaration are
decl-specifier:
storage-class-specifier
...
So in this declaration
static int s_One, s_Two;
the decl-specifier-seq
contains two decl-specifiers
, static
(storage class specifier) and int
. Thus the storage class specifier static
describes the both variables in the init-declarator-list
s_One
and s_Two
.
edited 8 hours ago
answered 8 hours ago
Vlad from MoscowVlad from Moscow
148k13 gold badges89 silver badges188 bronze badges
148k13 gold badges89 silver badges188 bronze badges
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
@VladfromMoscow why?
– Henri
8 hours ago
3
@VladfromMoscow How is declaring two separatestatic
int
s invalid syntax?
– Jesper Juhl
8 hours ago
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
|
show 3 more comments
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
@VladfromMoscow why?
– Henri
8 hours ago
3
@VladfromMoscow How is declaring two separatestatic
int
s invalid syntax?
– Jesper Juhl
8 hours ago
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
1
1
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
That's not enough; this doesn't show that the SCS applies to both, just that is possible.
– Rakete1111
8 hours ago
3
3
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
No, it is not. Why do you say it is invalid?
– Doch88
8 hours ago
2
2
@VladfromMoscow why?
– Henri
8 hours ago
@VladfromMoscow why?
– Henri
8 hours ago
3
3
@VladfromMoscow How is declaring two separate
static
int
s invalid syntax?– Jesper Juhl
8 hours ago
@VladfromMoscow How is declaring two separate
static
int
s invalid syntax?– Jesper Juhl
8 hours ago
1
1
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
@Doch88 I did not see that there is a semicolon instead of comma.:)
– Vlad from Moscow
8 hours ago
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57362724%2fwhat-does-c-language-definition-say-about-the-extent-of-the-static-keyword%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This question can be answered by reading the standard. But, why don't you simply remove the ambiguity by declaring each variable on its own?
– Jesper Juhl
8 hours ago
9
@JesperJuhl: Arguably, most answers about C++ can be answered by reading the standard. But the standard is big and sometimes difficult to navigate.
– rodrigo
8 hours ago
@JesperJuhl The answer might also be valuable to other people.
– ruohola
7 hours ago