Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Guess what I found in MFC's source code?

Guess what I found in MFC's source code?

Scheduled Pinned Locked Moved The Lounge
c++question
75 Posts 25 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T toxcct

    gotos are inherited from assembly code and that is the main reason it exist in C/C++. in all ways, i find MFC and other microsoft library codes awful to read. for example, they implement some of their functions into the header files instead of writing it into CPP files. moreover, they abuse of the imbricated operations...


    TOXCCT >>> GEII power

    M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #52

    toxcct wrote: MFC and other microsoft library codes awful to read. for example, they implement some of their functions into the header files instead of writing it into CPP files. The whole STL implementation is all written in header files. For ex, <vector> ... Maxwell Chen

    T 1 Reply Last reply
    0
    • M Maxwell Chen

      toxcct wrote: MFC and other microsoft library codes awful to read. for example, they implement some of their functions into the header files instead of writing it into CPP files. The whole STL implementation is all written in header files. For ex, <vector> ... Maxwell Chen

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #53

      Maxwell Chen wrote: The whole STL implementation is all written in header files. yes, and it is what i reproach them. read the post i wrote just before yours here...


      TOXCCT >>> GEII power

      M 1 Reply Last reply
      0
      • T toxcct

        we've powerful loop that perform clean jumps. we are not writing assembly here, so, gotos must be avoided as much as possible. Don't forget a thing : your program must stay "DEBUGGABLE"


        TOXCCT >>> GEII power

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #54

        toxcct wrote: your program must stay "DEBUGGABLE" When talking about what non-debuggableness, it goes to exception-handling instead of goto jumps. In the old days when I was coding ADO stuff, for example:

        bool Some_ADO_Type::FooBar(...)
        {
        // ...
        // Everything is OK in the block.
        return true;
        } // Crashed here right after the (debug) yellow arrow passed this closing bracket.

        I traced deep into the hell bases... no idea why it threw such an exception, and no way to catch with VC++ 6. Finally, VC++ 7.x supports ISO C++, and there is such way:

        bool FooBie()
        try
        {
        return true;
        }
        catch(...)
        {
        return false;
        }

        to catch such kind of god-d__n evil exceptions! Maxwell Chen

        T 1 Reply Last reply
        0
        • M Maxwell Chen

          toxcct wrote: your program must stay "DEBUGGABLE" When talking about what non-debuggableness, it goes to exception-handling instead of goto jumps. In the old days when I was coding ADO stuff, for example:

          bool Some_ADO_Type::FooBar(...)
          {
          // ...
          // Everything is OK in the block.
          return true;
          } // Crashed here right after the (debug) yellow arrow passed this closing bracket.

          I traced deep into the hell bases... no idea why it threw such an exception, and no way to catch with VC++ 6. Finally, VC++ 7.x supports ISO C++, and there is such way:

          bool FooBie()
          try
          {
          return true;
          }
          catch(...)
          {
          return false;
          }

          to catch such kind of god-d__n evil exceptions! Maxwell Chen

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #55

          NOOOOOO i'm not talking about that :( i say that if one day, you have to rewrite your code, or just maintain it, it would be much better if you could understand what you wrote back ?! isn't it ??? :confused:


          TOXCCT >>> GEII power

          M 1 Reply Last reply
          0
          • T toxcct

            Maxwell Chen wrote: The whole STL implementation is all written in header files. yes, and it is what i reproach them. read the post i wrote just before yours here...


            TOXCCT >>> GEII power

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #56

            So you mean that there would be the header <vector> and the implementation, vector.cxx, in gcc or others!? Maxwell Chen

            T 1 Reply Last reply
            0
            • T toxcct

              i found this in "The C++ Language" from Bjarne Stroustrup, Chapter 13.7 : Organisation of the source code. (please appology mu english and my poor abilities in the translation (i've got the book, but in french). [...] In fact, the definition of out(), and all the declarations it depends on, are included into several compilation units. The compiler must generate the code (uniquely) when necessary, and optimize the reading multiple definitions process. In this strategy, the template functions are treatd exactly as inline functions. In this case, an obvious problem appears. Every element depending on the definition of out() is added into each file that use this function. Quantity of information that has to be treatd by the compiler is so considerably grown up. Another problem reside in the fact that users can become dependant on some declarations included uniquely for the out definition. This danger can be minimized while using namespaces, avoiding coding macros and reducing quantity of informations so included. The strategy of separate the compilation is the logical solution to this reasoning : if the template definition don't appear in the user code, none of its dependances can affect this code. This is why we split here the original out.c file into the following two :

              // out.h
              template<class T> void out (const T&);

              // out.c
              #include <iostream>
              #include "out.h"
              export template<class T> void out (const T& t) { std::cerr << t; }

              the out.c file now contain all the requiered information to define out(), and out.h only contain useful information to call it. A user will only have to include the declaration (interface) : #include "out.h" [...]. i let you notice that the definition and the implementation are well splited !!!


              TOXCCT >>> GEII power

              J Offline
              J Offline
              jan larsen
              wrote on last edited by
              #57

              Here is what I found simply by Googling: http://www.comeaucomputing.com/techtalk/templates/#whylinkerror[^] A little snippet:

              Why do I get a link error when compiling my templates?
              Some compilers require that all function templates need to be made available in every translation
              unit that it is used in. In effect, for those compilers, the bodies of template functions must be
              made available in a header file. To repeat: that means those compilers won't allow them to be
              defined in non-header files such as .cpp files. Furthermore, some compilers also require that
              some functions be defined inline inside a class, and not outside of one.
              Note that not all compilers require this. For instance, Comeau C++ does not in all cases (check
              out http://www.comeaucomputing.com/4.0/docs/userman/ati.html for details on our current setup).
              In short, Comeau C++ supports many models, including one which comes close to what the export
              keyword's intentions are (as an extension).

              And on this point, note that the C++ export keyword is intended to alleviate the original
              question. However, currently Comeau C++ is the only compiler known to support export. Therefore,
              some compilers use such extensions referred to in the previous paragraph, or you need to put the
              bodies of your functions in headers, if you are using a compiler which does not support export.

              So, the ability to put template implementations in the cpp file may be standard, I don't know, and you can't deduce it from reading "The C++ language", because Stroustrup is NOT responsible for that C++ standard, he is not Linus you know ;) But since very few compilers, and apparently none of the most used, are able to do it, you should just avoid trying. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

              T M 2 Replies Last reply
              0
              • P peterchen

                Every if is a goto, every for, while and do. The ?: operator is, function calls are, and returns are gotos to an adress that where picked up at a crowded plaza. try going without goto, and you will arrive nowhere. ;P


                Flirt harder, I'm a Coder
                mlog || Agile Programming | doxygen

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #58

                but do you write it explicitely ??? i don't think so ! that comes in the assembly code ! in C/C++, we use many powerful loop that we don't have to use gotos in the code, except of poor few exceptions...


                TOXCCT >>> GEII power

                P 1 Reply Last reply
                0
                • M Maxwell Chen

                  So you mean that there would be the header <vector> and the implementation, vector.cxx, in gcc or others!? Maxwell Chen

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #59

                  i don't say it's what they do, i say, they should


                  TOXCCT >>> GEII power

                  1 Reply Last reply
                  0
                  • J jan larsen

                    Here is what I found simply by Googling: http://www.comeaucomputing.com/techtalk/templates/#whylinkerror[^] A little snippet:

                    Why do I get a link error when compiling my templates?
                    Some compilers require that all function templates need to be made available in every translation
                    unit that it is used in. In effect, for those compilers, the bodies of template functions must be
                    made available in a header file. To repeat: that means those compilers won't allow them to be
                    defined in non-header files such as .cpp files. Furthermore, some compilers also require that
                    some functions be defined inline inside a class, and not outside of one.
                    Note that not all compilers require this. For instance, Comeau C++ does not in all cases (check
                    out http://www.comeaucomputing.com/4.0/docs/userman/ati.html for details on our current setup).
                    In short, Comeau C++ supports many models, including one which comes close to what the export
                    keyword's intentions are (as an extension).

                    And on this point, note that the C++ export keyword is intended to alleviate the original
                    question. However, currently Comeau C++ is the only compiler known to support export. Therefore,
                    some compilers use such extensions referred to in the previous paragraph, or you need to put the
                    bodies of your functions in headers, if you are using a compiler which does not support export.

                    So, the ability to put template implementations in the cpp file may be standard, I don't know, and you can't deduce it from reading "The C++ language", because Stroustrup is NOT responsible for that C++ standard, he is not Linus you know ;) But since very few compilers, and apparently none of the most used, are able to do it, you should just avoid trying. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #60

                    jan larsen wrote: Stroustrup is NOT responsible for that C++ standard, he is not Linus you know ahahah. so you mean Linus Torvald is instead ? mouaahhhahah export is defined in the C++ standard, whatever you think, and it's sad to see those compilers not to implement it. :(


                    TOXCCT >>> GEII power

                    J 1 Reply Last reply
                    0
                    • T toxcct

                      jan larsen wrote: Stroustrup is NOT responsible for that C++ standard, he is not Linus you know ahahah. so you mean Linus Torvald is instead ? mouaahhhahah export is defined in the C++ standard, whatever you think, and it's sad to see those compilers not to implement it. :(


                      TOXCCT >>> GEII power

                      J Offline
                      J Offline
                      jan larsen
                      wrote on last edited by
                      #61

                      toxcct wrote: ahahah. so you mean Linus Torvald is instead ? mouaahhhahah No, what I meant was that unlike Linus, Bjarne has let go of his invention and given the full control to the implementors. toxcct wrote: export is defined in the C++ standard, whatever you think, and it's sad to see those compilers not to implement it. I agree, but since it doesn't help to moan about it, it's better to just accept that you probably have to wait a few more years before using that feature. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                      1 Reply Last reply
                      0
                      • T toxcct

                        NOOOOOO i'm not talking about that :( i say that if one day, you have to rewrite your code, or just maintain it, it would be much better if you could understand what you wrote back ?! isn't it ??? :confused:


                        TOXCCT >>> GEII power

                        M Offline
                        M Offline
                        Maxwell Chen
                        wrote on last edited by
                        #62

                        Elegant way using goto is acceptable, just don't use goto in too queer way that nobody understands the code. As in the following program (ref: The Spigot Algorithm[^]), there's no goto used in it, but still hard to read the code, even though just some for loops:

                        long a=10000,b,c=2800,d,e,f[2801],g;
                        int main() {
                        for(;b-c ; ) f[++b]=a/5;
                        for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
                        for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
                        }

                        Maxwell Chen

                        T 2 Replies Last reply
                        0
                        • J jan larsen

                          Here is what I found simply by Googling: http://www.comeaucomputing.com/techtalk/templates/#whylinkerror[^] A little snippet:

                          Why do I get a link error when compiling my templates?
                          Some compilers require that all function templates need to be made available in every translation
                          unit that it is used in. In effect, for those compilers, the bodies of template functions must be
                          made available in a header file. To repeat: that means those compilers won't allow them to be
                          defined in non-header files such as .cpp files. Furthermore, some compilers also require that
                          some functions be defined inline inside a class, and not outside of one.
                          Note that not all compilers require this. For instance, Comeau C++ does not in all cases (check
                          out http://www.comeaucomputing.com/4.0/docs/userman/ati.html for details on our current setup).
                          In short, Comeau C++ supports many models, including one which comes close to what the export
                          keyword's intentions are (as an extension).

                          And on this point, note that the C++ export keyword is intended to alleviate the original
                          question. However, currently Comeau C++ is the only compiler known to support export. Therefore,
                          some compilers use such extensions referred to in the previous paragraph, or you need to put the
                          bodies of your functions in headers, if you are using a compiler which does not support export.

                          So, the ability to put template implementations in the cpp file may be standard, I don't know, and you can't deduce it from reading "The C++ language", because Stroustrup is NOT responsible for that C++ standard, he is not Linus you know ;) But since very few compilers, and apparently none of the most used, are able to do it, you should just avoid trying. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                          M Offline
                          M Offline
                          Maxwell Chen
                          wrote on last edited by
                          #63

                          I am not sure if I remembered correctly ... In some situation, a function template needs to be instantiated when across compilation units... If wrong, just forget it... ;P Maxwell Chen

                          1 Reply Last reply
                          0
                          • M Maxwell Chen

                            Elegant way using goto is acceptable, just don't use goto in too queer way that nobody understands the code. As in the following program (ref: The Spigot Algorithm[^]), there's no goto used in it, but still hard to read the code, even though just some for loops:

                            long a=10000,b,c=2800,d,e,f[2801],g;
                            int main() {
                            for(;b-c ; ) f[++b]=a/5;
                            for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
                            for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
                            }

                            Maxwell Chen

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #64

                            i did never say that "elegant" was without gotos. of course that code is awful ! grrrrrrrr


                            TOXCCT >>> GEII power

                            1 Reply Last reply
                            0
                            • M Maxwell Chen

                              Elegant way using goto is acceptable, just don't use goto in too queer way that nobody understands the code. As in the following program (ref: The Spigot Algorithm[^]), there's no goto used in it, but still hard to read the code, even though just some for loops:

                              long a=10000,b,c=2800,d,e,f[2801],g;
                              int main() {
                              for(;b-c ; ) f[++b]=a/5;
                              for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
                              for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
                              }

                              Maxwell Chen

                              T Offline
                              T Offline
                              toxcct
                              wrote on last edited by
                              #65

                              ......... and you dare show us that....! :laugh::wtf::doh:


                              TOXCCT >>> GEII power

                              M 1 Reply Last reply
                              0
                              • T toxcct

                                ......... and you dare show us that....! :laugh::wtf::doh:


                                TOXCCT >>> GEII power

                                M Offline
                                M Offline
                                Maxwell Chen
                                wrote on last edited by
                                #66

                                Ha ha... ;P That is a famous algorithm that computes pi, with merely 150 characters in a small C program. :cool: Maxwell Chen

                                T 1 Reply Last reply
                                0
                                • M Maxwell Chen

                                  Ha ha... ;P That is a famous algorithm that computes pi, with merely 150 characters in a small C program. :cool: Maxwell Chen

                                  T Offline
                                  T Offline
                                  toxcct
                                  wrote on last edited by
                                  #67

                                  and so powerful and useful mean beautiful for you ? :cool:


                                  TOXCCT >>> GEII power

                                  M 2 Replies Last reply
                                  0
                                  • T toxcct

                                    and so powerful and useful mean beautiful for you ? :cool:


                                    TOXCCT >>> GEII power

                                    M Offline
                                    M Offline
                                    Maxwell Chen
                                    wrote on last edited by
                                    #68

                                    toxcct wrote: and so powerful and useful mean beautiful for you ? No, I don't understand the code either! :doh: X| ;P Maxwell Chen

                                    1 Reply Last reply
                                    0
                                    • T toxcct

                                      and so powerful and useful mean beautiful for you ? :cool:


                                      TOXCCT >>> GEII power

                                      M Offline
                                      M Offline
                                      Maxwell Chen
                                      wrote on last edited by
                                      #69

                                      From your bio: but in C/C++ (my favorites) since 1998. Hey, I started studying C++ since Nov 1998! :-D Maxwell Chen

                                      T 1 Reply Last reply
                                      0
                                      • M Maxwell Chen

                                        From your bio: but in C/C++ (my favorites) since 1998. Hey, I started studying C++ since Nov 1998! :-D Maxwell Chen

                                        T Offline
                                        T Offline
                                        toxcct
                                        wrote on last edited by
                                        #70

                                        well, what should i answer that ?! eheh welcome on board :-D


                                        TOXCCT >>> GEII power

                                        M 1 Reply Last reply
                                        0
                                        • T toxcct

                                          well, what should i answer that ?! eheh welcome on board :-D


                                          TOXCCT >>> GEII power

                                          M Offline
                                          M Offline
                                          Maxwell Chen
                                          wrote on last edited by
                                          #71

                                          Since we both started C++ programming after the ISO C++ Standard has come out, how do you consider the ISO standard? Five years more passed and I've been working for three companies (this is my 3rd job now), all those of my colleagues (including ex-colleagues) who started programming C/C++ since Windows 3.1 / DOS era, don't care about ISO/IEC 14882 at all. They think VC++ 6 just fine, and even don't know what the C++ Standard is! :( Maxwell Chen

                                          T 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups