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. I have a great idea for an article but I lack the words

I have a great idea for an article but I lack the words

Scheduled Pinned Locked Moved The Lounge
designc++visual-studiowpfwcf
21 Posts 7 Posters 3 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.
  • honey the codewitchH honey the codewitch

    It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

    J Offline
    J Offline
    jmaida
    wrote on last edited by
    #2

    Not sure I understand, but I have done this. I have an large array of function addresses. They are indexed by "name" using a hash table and executed at run time. ???

    "A little time, a little trouble, your better day" Badfinger

    honey the codewitchH 1 Reply Last reply
    0
    • J jmaida

      Not sure I understand, but I have done this. I have an large array of function addresses. They are indexed by "name" using a hash table and executed at run time. ???

      "A little time, a little trouble, your better day" Badfinger

      honey the codewitchH Offline
      honey the codewitchH Offline
      honey the codewitch
      wrote on last edited by
      #3

      I'm referring to a vtbl, which is created by the C++ compiler. in memory it exists as an array of pointers to functions. However, each function signature is potentially different than the next.

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

      J 1 Reply Last reply
      0
      • honey the codewitchH honey the codewitch

        It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        "Extending".

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        J honey the codewitchH 2 Replies Last reply
        0
        • honey the codewitchH honey the codewitch

          It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          Mike HankeyM Offline
          Mike HankeyM Offline
          Mike Hankey
          wrote on last edited by
          #5

          Interesting idea, don't know as I've ever seen anything on this subject before. Maybe? C++ Binding Mechanisms

          I don't think before I open my mouth, I like to be as surprised a everyone else. PartsBin an Electronics Part Organizer - Release Version 1.1.0 JaxCoder.com Latest Article: SimpleWizardUpdate

          honey the codewitchH 1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            I'm referring to a vtbl, which is created by the C++ compiler. in memory it exists as an array of pointers to functions. However, each function signature is potentially different than the next.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            J Offline
            J Offline
            jmaida
            wrote on last edited by
            #6

            I understand. My implementation was pure C. Not being a C++ expert, I may not be interpreting your approach the same.

            "A little time, a little trouble, your better day" Badfinger

            honey the codewitchH 1 Reply Last reply
            0
            • L Lost User

              "Extending".

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

              J Offline
              J Offline
              jmaida
              wrote on last edited by
              #7

              Extending???

              "A little time, a little trouble, your better day" Badfinger

              L 1 Reply Last reply
              0
              • J jmaida

                I understand. My implementation was pure C. Not being a C++ expert, I may not be interpreting your approach the same.

                "A little time, a little trouble, your better day" Badfinger

                honey the codewitchH Offline
                honey the codewitchH Offline
                honey the codewitch
                wrote on last edited by
                #8

                It was close. Subtract the hashtable, and make it so every pointer potentially points to a different sig of function. You can't make the construct yourself in pure C or C++ without hackery, but the C++ compiler makes them as I said. What they do is they point to each "virtual" method in a class. Like in C#, virtual methods can be overridden. When that happens, the corresponding function pointer in the vtbl is corrected with the new function.

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                J 1 Reply Last reply
                0
                • Mike HankeyM Mike Hankey

                  Interesting idea, don't know as I've ever seen anything on this subject before. Maybe? C++ Binding Mechanisms

                  I don't think before I open my mouth, I like to be as surprised a everyone else. PartsBin an Electronics Part Organizer - Release Version 1.1.0 JaxCoder.com Latest Article: SimpleWizardUpdate

                  honey the codewitchH Offline
                  honey the codewitchH Offline
                  honey the codewitch
                  wrote on last edited by
                  #9

                  That sounds decent

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  1 Reply Last reply
                  0
                  • L Lost User

                    "Extending".

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    honey the codewitchH Offline
                    honey the codewitchH Offline
                    honey the codewitch
                    wrote on last edited by
                    #10

                    I'm not sure that hits the mark. The thing is, extending strikes me as something you do to a class by subclassing it.

                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                    L 1 Reply Last reply
                    0
                    • honey the codewitchH honey the codewitch

                      It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      A Offline
                      A Offline
                      Andreas Saurwein
                      wrote on last edited by
                      #11

                      "C++ Magick only very few need to understand" what about this as title? :laugh:


                      forging iron and new ideas

                      1 Reply Last reply
                      0
                      • honey the codewitchH honey the codewitch

                        I'm not sure that hits the mark. The thing is, extending strikes me as something you do to a class by subclassing it.

                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #12

                        I use "component based" architecture. I have objects to which I can add a "time / duration" or "distance" or "angle" object (among others) at run time; which then dictates what the object does until the condition created by the new component is satisfied; at which time, this "extender" is removed. [later]

                        Quote:

                        In computing, a plug-in (or plugin, add-in, addin, add-on, or addon) is a software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization.

                        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                        honey the codewitchH 1 Reply Last reply
                        0
                        • J jmaida

                          Extending???

                          "A little time, a little trouble, your better day" Badfinger

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          The post was regarding: a "thing" within a thing, and operating on that thing. I add functionality to some of my existing components by adding "another" component which influences the behaviour of the original component until a certain condition is satisfied. e.g. My "units" have standard movements. In the case of a "wheel", a "wheeling" object is added; which adds a pivot point and "sweep" to its movements, affecting a wheel movement until a given angle is passed. Then it removes the component and reverts back to its standard behaviour. (It's not "inheritance")

                          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                          1 Reply Last reply
                          0
                          • honey the codewitchH honey the codewitch

                            It was close. Subtract the hashtable, and make it so every pointer potentially points to a different sig of function. You can't make the construct yourself in pure C or C++ without hackery, but the C++ compiler makes them as I said. What they do is they point to each "virtual" method in a class. Like in C#, virtual methods can be overridden. When that happens, the corresponding function pointer in the vtbl is corrected with the new function.

                            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                            J Offline
                            J Offline
                            jschell
                            wrote on last edited by
                            #14

                            honey the codewitch wrote:

                            ou can't make the construct yourself in pure C or C++ without hackery,

                            Not sure I believe that. Following is pseudo code obviously but I know it can be implemented both in C and C++. So what part is considered a 'hack'?

                            // Initialize function pointers.
                            functionPointers[15] = ...

                            // Set up class
                            struct MyClass
                            {
                            private function1pointer = &functionPointers[2]

                            public void Function1(int v)
                            {
                            function1pointer(v);
                            }
                            }

                            honey the codewitchH 1 Reply Last reply
                            0
                            • honey the codewitchH honey the codewitch

                              It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

                              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #15

                              honey the codewitch wrote:

                              passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class.

                              Not sure how a compiler might do that now but certainly in the past it did it by creating a new class. Basically a hidden class as part of the binary build. One can of course explicitly code the same. But one would need to do it for each case. I did that (explicit) on occasion long ago with the early Templates in C++ because the error messages in the stack traces were useless. You could even code that dynamically by just duplicating what the compiler does. Seems like it would be more useful though to explain how a compiler does that, with assembler examples, rather than attempting it from scratch. Or, I suspect, do not some C++ compilers still allow one to have it emit C rather than assembler? That would be easier (probably) to use as a demonstration of what is happening.

                              honey the codewitchH 1 Reply Last reply
                              0
                              • J jschell

                                honey the codewitch wrote:

                                ou can't make the construct yourself in pure C or C++ without hackery,

                                Not sure I believe that. Following is pseudo code obviously but I know it can be implemented both in C and C++. So what part is considered a 'hack'?

                                // Initialize function pointers.
                                functionPointers[15] = ...

                                // Set up class
                                struct MyClass
                                {
                                private function1pointer = &functionPointers[2]

                                public void Function1(int v)
                                {
                                function1pointer(v);
                                }
                                }

                                honey the codewitchH Offline
                                honey the codewitchH Offline
                                honey the codewitch
                                wrote on last edited by
                                #16

                                they all have to have the same sig though. Or you have to use void* and cast them before you make the call.

                                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                J 1 Reply Last reply
                                0
                                • J jschell

                                  honey the codewitch wrote:

                                  passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class.

                                  Not sure how a compiler might do that now but certainly in the past it did it by creating a new class. Basically a hidden class as part of the binary build. One can of course explicitly code the same. But one would need to do it for each case. I did that (explicit) on occasion long ago with the early Templates in C++ because the error messages in the stack traces were useless. You could even code that dynamically by just duplicating what the compiler does. Seems like it would be more useful though to explain how a compiler does that, with assembler examples, rather than attempting it from scratch. Or, I suspect, do not some C++ compilers still allow one to have it emit C rather than assembler? That would be easier (probably) to use as a demonstration of what is happening.

                                  honey the codewitchH Offline
                                  honey the codewitchH Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #17

                                  jschell wrote:

                                  Or, I suspect, do not some C++ compilers still allow one to have it emit C rather than assembler? That would be easier (probably) to use as a demonstration of what is happening.

                                  I'm not sure how to do that with MSVC, GCC or Clang to be honest.

                                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                  J 1 Reply Last reply
                                  0
                                  • L Lost User

                                    I use "component based" architecture. I have objects to which I can add a "time / duration" or "distance" or "angle" object (among others) at run time; which then dictates what the object does until the condition created by the new component is satisfied; at which time, this "extender" is removed. [later]

                                    Quote:

                                    In computing, a plug-in (or plugin, add-in, addin, add-on, or addon) is a software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization.

                                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                    honey the codewitchH Offline
                                    honey the codewitchH Offline
                                    honey the codewitch
                                    wrote on last edited by
                                    #18

                                    That's binary binding. C++ also allows a kind of source level binding (actually all languages do, but not like this - I'm not sure how to explain the difference exactly except to compare and contrast it to the sort of binding you're talking about)

                                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                    1 Reply Last reply
                                    0
                                    • honey the codewitchH honey the codewitch

                                      It would be great to do an exploration of binary vs source level binding in C++ but I'm not sure what you'd call it. For example, a pure virtual class (interface) is a binary binding mechanism. You are essentially passing around a table of function pointers. You can pass a class *instance* as a *function* argument and bind to it at run time. An example of "source level binding" (if you want to call it that) would be passing a class as a template argument to a template class, and then operating on the first class's methods from inside the second class. Anyone have any ideas?

                                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                      G Offline
                                      G Offline
                                      Gary R Wheeler
                                      wrote on last edited by
                                      #19

                                      Comparing C++ Inheritance To Template Metaprogramming: Compiler and Runtime Metrics Writing the article is left as an exercise for the student.

                                      Software Zen: delete this;

                                      1 Reply Last reply
                                      0
                                      • honey the codewitchH honey the codewitch

                                        jschell wrote:

                                        Or, I suspect, do not some C++ compilers still allow one to have it emit C rather than assembler? That would be easier (probably) to use as a demonstration of what is happening.

                                        I'm not sure how to do that with MSVC, GCC or Clang to be honest.

                                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                        J Offline
                                        J Offline
                                        jschell
                                        wrote on last edited by
                                        #20

                                        Appears to still be possible. Standard C++[^]

                                        1 Reply Last reply
                                        0
                                        • honey the codewitchH honey the codewitch

                                          they all have to have the same sig though. Or you have to use void* and cast them before you make the call.

                                          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                          J Offline
                                          J Offline
                                          jschell
                                          wrote on last edited by
                                          #21

                                          honey the codewitch wrote:

                                          they all have to have the same sig though.

                                          Ah...I see what you mean now by the hack part.

                                          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