Scope of typedefs












8















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?










share|improve this question



























    8















    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?










    share|improve this question

























      8












      8








      8








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 25 '12 at 8:37









      FiredragonFiredragon

      2,13622162




      2,13622162
























          4 Answers
          4






          active

          oldest

          votes


















          22














          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.






          share|improve this answer
























          • Thanks, that makes sense.

            – Firedragon
            Apr 25 '12 at 8:44



















          5














          typedef has the same scope as regular variables in C/C++






          share|improve this answer































            1














            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.






            share|improve this answer































              0














              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;





              share|improve this answer























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









                22














                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.






                share|improve this answer
























                • Thanks, that makes sense.

                  – Firedragon
                  Apr 25 '12 at 8:44
















                22














                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.






                share|improve this answer
























                • Thanks, that makes sense.

                  – Firedragon
                  Apr 25 '12 at 8:44














                22












                22








                22







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 25 '12 at 8:40









                unwindunwind

                320k52394526




                320k52394526













                • 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





                Thanks, that makes sense.

                – Firedragon
                Apr 25 '12 at 8:44













                5














                typedef has the same scope as regular variables in C/C++






                share|improve this answer




























                  5














                  typedef has the same scope as regular variables in C/C++






                  share|improve this answer


























                    5












                    5








                    5







                    typedef has the same scope as regular variables in C/C++






                    share|improve this answer













                    typedef has the same scope as regular variables in C/C++







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 25 '12 at 8:40









                    mihaimihai

                    23.9k74068




                    23.9k74068























                        1














                        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.






                        share|improve this answer




























                          1














                          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.






                          share|improve this answer


























                            1












                            1








                            1







                            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.






                            share|improve this answer













                            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.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Oct 23 '12 at 16:18









                            bubblebubble

                            1,74642248




                            1,74642248























                                0














                                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;





                                share|improve this answer




























                                  0














                                  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;





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    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;





                                    share|improve this answer













                                    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;






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 19 '18 at 23:47









                                    MattWMattW

                                    605




                                    605






























                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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

                                        How to change which sound is reproduced for terminal bell?

                                        Can I use Tabulator js library in my java Spring + Thymeleaf project?

                                        Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents