Namespaces in C formal definition












1














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...".










share|improve this question




















  • 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














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...".










share|improve this question




















  • 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








1







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...".










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 7:46









Jonathan Leffler

561k896661018




561k896661018










asked Nov 23 '18 at 7:02









Some NameSome Name

830214




830214








  • 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




    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














1 Answer
1






active

oldest

votes


















6














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.






share|improve this answer



















  • 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 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











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
});


}
});














draft saved

draft discarded


















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









6














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.






share|improve this answer



















  • 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 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
















6














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.






share|improve this answer



















  • 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 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














6












6








6






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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 7:44

























answered Nov 23 '18 at 7:14









Sourav GhoshSourav Ghosh

109k14129187




109k14129187








  • 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 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














  • 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 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








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


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...