Namespaces in C formal definition
I'm reading the N1570 Standard and have a problem to understand the wording of the name space definition. Here is it:
1 If more than one declaration of a particular identifier is visible
at any point in a translation unit, the syntactic context
disambiguates uses that refer to different entities. Thus, there are
separate name spaces for various categories of identifiers, as
follows:
— label names (disambiguated by the syntax of the label
declaration and use);
— the tags of structures, unions, and
enumerations (disambiguated by following any32) of the keywords
struct, union, or enum);
— the members of structures or unions; each
structure or union has a separate name space for its members
(disambiguated by the type of the expression used to access the member
via the.
or->
operator);
— all other identifiers, called ordinary
identifiers (declared in ordinary declarators or as enumeration
constants).
32) There is only one name space for tags even though three are possible.
Here they are talking about in case of more than 1 declaration of particular identifiers is visible. Now words something like "To access an identifier one shall specify its namespace" or "To access an identifier in a specific namespace...".
c namespaces language-lawyer
add a comment |
I'm reading the N1570 Standard and have a problem to understand the wording of the name space definition. Here is it:
1 If more than one declaration of a particular identifier is visible
at any point in a translation unit, the syntactic context
disambiguates uses that refer to different entities. Thus, there are
separate name spaces for various categories of identifiers, as
follows:
— label names (disambiguated by the syntax of the label
declaration and use);
— the tags of structures, unions, and
enumerations (disambiguated by following any32) of the keywords
struct, union, or enum);
— the members of structures or unions; each
structure or union has a separate name space for its members
(disambiguated by the type of the expression used to access the member
via the.
or->
operator);
— all other identifiers, called ordinary
identifiers (declared in ordinary declarators or as enumeration
constants).
32) There is only one name space for tags even though three are possible.
Here they are talking about in case of more than 1 declaration of particular identifiers is visible. Now words something like "To access an identifier one shall specify its namespace" or "To access an identifier in a specific namespace...".
c namespaces language-lawyer
1
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49
add a comment |
I'm reading the N1570 Standard and have a problem to understand the wording of the name space definition. Here is it:
1 If more than one declaration of a particular identifier is visible
at any point in a translation unit, the syntactic context
disambiguates uses that refer to different entities. Thus, there are
separate name spaces for various categories of identifiers, as
follows:
— label names (disambiguated by the syntax of the label
declaration and use);
— the tags of structures, unions, and
enumerations (disambiguated by following any32) of the keywords
struct, union, or enum);
— the members of structures or unions; each
structure or union has a separate name space for its members
(disambiguated by the type of the expression used to access the member
via the.
or->
operator);
— all other identifiers, called ordinary
identifiers (declared in ordinary declarators or as enumeration
constants).
32) There is only one name space for tags even though three are possible.
Here they are talking about in case of more than 1 declaration of particular identifiers is visible. Now words something like "To access an identifier one shall specify its namespace" or "To access an identifier in a specific namespace...".
c namespaces language-lawyer
I'm reading the N1570 Standard and have a problem to understand the wording of the name space definition. Here is it:
1 If more than one declaration of a particular identifier is visible
at any point in a translation unit, the syntactic context
disambiguates uses that refer to different entities. Thus, there are
separate name spaces for various categories of identifiers, as
follows:
— label names (disambiguated by the syntax of the label
declaration and use);
— the tags of structures, unions, and
enumerations (disambiguated by following any32) of the keywords
struct, union, or enum);
— the members of structures or unions; each
structure or union has a separate name space for its members
(disambiguated by the type of the expression used to access the member
via the.
or->
operator);
— all other identifiers, called ordinary
identifiers (declared in ordinary declarators or as enumeration
constants).
32) There is only one name space for tags even though three are possible.
Here they are talking about in case of more than 1 declaration of particular identifiers is visible. Now words something like "To access an identifier one shall specify its namespace" or "To access an identifier in a specific namespace...".
c namespaces language-lawyer
c namespaces language-lawyer
edited Nov 23 '18 at 7:46
Jonathan Leffler
566k916781029
566k916781029
asked Nov 23 '18 at 7:02
Some NameSome Name
1,085416
1,085416
1
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49
add a comment |
1
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49
1
1
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49
add a comment |
1 Answer
1
active
oldest
votes
Let me show an example first (this is strictly for understanding purpose, dont write code like this, ever)
#include <stdio.h>
int main(void)
{
int here = 0; //.......................ordinary identifier
struct here { //.......................structure tag
int here; //.......................member of a structure
} there;
here: //......... a label name
here++;
printf("Inside heren");
there.here = here; //...........no conflict, both are in separate namespace
if (here > 2) {
return 0;
}
else
goto here; //......... a label name
printf("Hello, world!n"); // control does not reach here..intentionally :)
return 0;
}
You see usage of identifier here
. They belong to separate namespace(s) according to the rule, hence this program is fine.
However, say, for example, you change the structure variable name, from there
to here
, and you'll see a conflict, as then, there would be two separate declaration of same identifier (ordinary identifier) in the same namespace.
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
@Lundin: It's quantum physical code — it is bothhere
andthere
.
– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
add a comment |
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%2f53442007%2fnamespaces-in-c-formal-definition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let me show an example first (this is strictly for understanding purpose, dont write code like this, ever)
#include <stdio.h>
int main(void)
{
int here = 0; //.......................ordinary identifier
struct here { //.......................structure tag
int here; //.......................member of a structure
} there;
here: //......... a label name
here++;
printf("Inside heren");
there.here = here; //...........no conflict, both are in separate namespace
if (here > 2) {
return 0;
}
else
goto here; //......... a label name
printf("Hello, world!n"); // control does not reach here..intentionally :)
return 0;
}
You see usage of identifier here
. They belong to separate namespace(s) according to the rule, hence this program is fine.
However, say, for example, you change the structure variable name, from there
to here
, and you'll see a conflict, as then, there would be two separate declaration of same identifier (ordinary identifier) in the same namespace.
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
@Lundin: It's quantum physical code — it is bothhere
andthere
.
– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
add a comment |
Let me show an example first (this is strictly for understanding purpose, dont write code like this, ever)
#include <stdio.h>
int main(void)
{
int here = 0; //.......................ordinary identifier
struct here { //.......................structure tag
int here; //.......................member of a structure
} there;
here: //......... a label name
here++;
printf("Inside heren");
there.here = here; //...........no conflict, both are in separate namespace
if (here > 2) {
return 0;
}
else
goto here; //......... a label name
printf("Hello, world!n"); // control does not reach here..intentionally :)
return 0;
}
You see usage of identifier here
. They belong to separate namespace(s) according to the rule, hence this program is fine.
However, say, for example, you change the structure variable name, from there
to here
, and you'll see a conflict, as then, there would be two separate declaration of same identifier (ordinary identifier) in the same namespace.
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
@Lundin: It's quantum physical code — it is bothhere
andthere
.
– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
add a comment |
Let me show an example first (this is strictly for understanding purpose, dont write code like this, ever)
#include <stdio.h>
int main(void)
{
int here = 0; //.......................ordinary identifier
struct here { //.......................structure tag
int here; //.......................member of a structure
} there;
here: //......... a label name
here++;
printf("Inside heren");
there.here = here; //...........no conflict, both are in separate namespace
if (here > 2) {
return 0;
}
else
goto here; //......... a label name
printf("Hello, world!n"); // control does not reach here..intentionally :)
return 0;
}
You see usage of identifier here
. They belong to separate namespace(s) according to the rule, hence this program is fine.
However, say, for example, you change the structure variable name, from there
to here
, and you'll see a conflict, as then, there would be two separate declaration of same identifier (ordinary identifier) in the same namespace.
Let me show an example first (this is strictly for understanding purpose, dont write code like this, ever)
#include <stdio.h>
int main(void)
{
int here = 0; //.......................ordinary identifier
struct here { //.......................structure tag
int here; //.......................member of a structure
} there;
here: //......... a label name
here++;
printf("Inside heren");
there.here = here; //...........no conflict, both are in separate namespace
if (here > 2) {
return 0;
}
else
goto here; //......... a label name
printf("Hello, world!n"); // control does not reach here..intentionally :)
return 0;
}
You see usage of identifier here
. They belong to separate namespace(s) according to the rule, hence this program is fine.
However, say, for example, you change the structure variable name, from there
to here
, and you'll see a conflict, as then, there would be two separate declaration of same identifier (ordinary identifier) in the same namespace.
edited Nov 23 '18 at 7:44
answered Nov 23 '18 at 7:14
Sourav GhoshSourav Ghosh
110k14130188
110k14130188
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
@Lundin: It's quantum physical code — it is bothhere
andthere
.
– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
add a comment |
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
@Lundin: It's quantum physical code — it is bothhere
andthere
.
– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
1
1
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
I believe this code is neither here nor there :)
– Lundin
Nov 23 '18 at 7:48
1
1
@Lundin: It's quantum physical code — it is both
here
and there
.– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin: It's quantum physical code — it is both
here
and there
.– Jonathan Leffler
Nov 23 '18 at 7:52
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
@Lundin It's somewhere, I guess...not count the time factor, either. :)
– Sourav Ghosh
Nov 23 '18 at 7:53
add a comment |
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%2f53442007%2fnamespaces-in-c-formal-definition%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
1
What's your question? In case you are thinking about C++ namespaces, that's entirely different.
– Nelfeal
Nov 23 '18 at 7:07
@Nelfeal Defnitely not about C++ namespaces. I want to uderstand the percise meaning of namespaces in C and rules how to work with them.
– Some Name
Nov 23 '18 at 7:08
Note that macros cut across all these namespaces indiscriminately, but they've ceased to be an issue by the time these namespaces are discussed. (C11 §6.2.1 Scopes of identifiers ¶1: Macro names and macro parameters are not considered further here, because prior to the semantic phase of program translation any occurrences of macro names in the source file are replaced by the preprocessing token sequences that constitute their macro definitions.)
– Jonathan Leffler
Nov 23 '18 at 7:49