Scope of typedefs
I am not at a computer so cannot test this at the moment but have some code to review. I'm still somewhat in a C++ mindframe unfortunatley.
So, when a typedef is declared within a C source file what is its scope? I am aware that to make functions and variables only available within the same translation unit you need to make them static and I was wondering if this is the same for typedefs?
c
add a comment |
I am not at a computer so cannot test this at the moment but have some code to review. I'm still somewhat in a C++ mindframe unfortunatley.
So, when a typedef is declared within a C source file what is its scope? I am aware that to make functions and variables only available within the same translation unit you need to make them static and I was wondering if this is the same for typedefs?
c
add a comment |
I am not at a computer so cannot test this at the moment but have some code to review. I'm still somewhat in a C++ mindframe unfortunatley.
So, when a typedef is declared within a C source file what is its scope? I am aware that to make functions and variables only available within the same translation unit you need to make them static and I was wondering if this is the same for typedefs?
c
I am not at a computer so cannot test this at the moment but have some code to review. I'm still somewhat in a C++ mindframe unfortunatley.
So, when a typedef is declared within a C source file what is its scope? I am aware that to make functions and variables only available within the same translation unit you need to make them static and I was wondering if this is the same for typedefs?
c
c
asked Apr 25 '12 at 8:37
FiredragonFiredragon
2,13622162
2,13622162
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Typedefs are declarations. If you have a typedef in a C file, no other C file will be aware of that since they are compiled indepedendly of each other.
For a typedef in a header, it will of course be visible from all C files that include it.
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
add a comment |
typedef
has the same scope as regular variables in C/C++
add a comment |
I dont know whats the meaning of this complex sentence but this is how C standard defines the scope of typedefs:
As a special case, a type name (which is not a declaration of an identifier) is considered to
have a scope that begins just after the place within the type name where the omitted
identifier would appear were it not omitted.
P.S. Somebody please explain.
add a comment |
Here is an example showing typedef and scope:
typedef int foo_t;
foo_t x = 1;
double bar(double x) {
typedef double foo_t;
foo_t y = 2.0;
return y + 3.14156;
}
foo_t z = 1;
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%2f10312147%2fscope-of-typedefs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Typedefs are declarations. If you have a typedef in a C file, no other C file will be aware of that since they are compiled indepedendly of each other.
For a typedef in a header, it will of course be visible from all C files that include it.
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
add a comment |
Typedefs are declarations. If you have a typedef in a C file, no other C file will be aware of that since they are compiled indepedendly of each other.
For a typedef in a header, it will of course be visible from all C files that include it.
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
add a comment |
Typedefs are declarations. If you have a typedef in a C file, no other C file will be aware of that since they are compiled indepedendly of each other.
For a typedef in a header, it will of course be visible from all C files that include it.
Typedefs are declarations. If you have a typedef in a C file, no other C file will be aware of that since they are compiled indepedendly of each other.
For a typedef in a header, it will of course be visible from all C files that include it.
answered Apr 25 '12 at 8:40
unwindunwind
320k52394526
320k52394526
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
add a comment |
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
Thanks, that makes sense.
– Firedragon
Apr 25 '12 at 8:44
add a comment |
typedef
has the same scope as regular variables in C/C++
add a comment |
typedef
has the same scope as regular variables in C/C++
add a comment |
typedef
has the same scope as regular variables in C/C++
typedef
has the same scope as regular variables in C/C++
answered Apr 25 '12 at 8:40
mihaimihai
23.9k74068
23.9k74068
add a comment |
add a comment |
I dont know whats the meaning of this complex sentence but this is how C standard defines the scope of typedefs:
As a special case, a type name (which is not a declaration of an identifier) is considered to
have a scope that begins just after the place within the type name where the omitted
identifier would appear were it not omitted.
P.S. Somebody please explain.
add a comment |
I dont know whats the meaning of this complex sentence but this is how C standard defines the scope of typedefs:
As a special case, a type name (which is not a declaration of an identifier) is considered to
have a scope that begins just after the place within the type name where the omitted
identifier would appear were it not omitted.
P.S. Somebody please explain.
add a comment |
I dont know whats the meaning of this complex sentence but this is how C standard defines the scope of typedefs:
As a special case, a type name (which is not a declaration of an identifier) is considered to
have a scope that begins just after the place within the type name where the omitted
identifier would appear were it not omitted.
P.S. Somebody please explain.
I dont know whats the meaning of this complex sentence but this is how C standard defines the scope of typedefs:
As a special case, a type name (which is not a declaration of an identifier) is considered to
have a scope that begins just after the place within the type name where the omitted
identifier would appear were it not omitted.
P.S. Somebody please explain.
answered Oct 23 '12 at 16:18
bubblebubble
1,74642248
1,74642248
add a comment |
add a comment |
Here is an example showing typedef and scope:
typedef int foo_t;
foo_t x = 1;
double bar(double x) {
typedef double foo_t;
foo_t y = 2.0;
return y + 3.14156;
}
foo_t z = 1;
add a comment |
Here is an example showing typedef and scope:
typedef int foo_t;
foo_t x = 1;
double bar(double x) {
typedef double foo_t;
foo_t y = 2.0;
return y + 3.14156;
}
foo_t z = 1;
add a comment |
Here is an example showing typedef and scope:
typedef int foo_t;
foo_t x = 1;
double bar(double x) {
typedef double foo_t;
foo_t y = 2.0;
return y + 3.14156;
}
foo_t z = 1;
Here is an example showing typedef and scope:
typedef int foo_t;
foo_t x = 1;
double bar(double x) {
typedef double foo_t;
foo_t y = 2.0;
return y + 3.14156;
}
foo_t z = 1;
answered Nov 19 '18 at 23:47
MattWMattW
605
605
add a comment |
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%2f10312147%2fscope-of-typedefs%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