Viewing 20 posts - 181 through 200 (of 259 total)
  • Author
    Posts
  • #66413
    Wheels-Of-FireWheels-Of-Fire
    Participant
      @grahamdearsley
      Forumite Points: 4

      It turns out that the implied “this” parameter is not too complicated on its own, where a class member  function may have had to specify a data member explicitly, it doesn’t have to if they are both in the same class. Implied “this” gets complicated with return types because there is no actual “this” type to return. C++ lets you specify a return type, such as const, after the parameter list.

      I am coming back to it !

      In the mean time I am looking at double ended queue types (A dequeue), looks like a vector that supports push_front as well as push_back.

      #67047
      Wheels-Of-FireWheels-Of-Fire
      Participant
        @grahamdearsley
        Forumite Points: 4

        Lambda expressions today.

        Why “Lambda” ? I think it has more to do with the sub atomic particle of that name than it does to do with Lambda calculus, a Lambda expression is a small callable object that is attached to a larger function.

        This is my understanding.

        A Lambda expression is an unnamed function that can be passed to a larger function as an argument. Lambda’s have a parameter list as usual but they also have a list of local variables that they can capture from the function they are passed to.

        Why would you use a Lambda ? The main reason seems to be if you need to pass more parameters to a function than it supports. If you were writing the function yourself then you would just design it to take more arguments but you can’t do that with library functions. The biggest users of lambda’s seem to be the general purpose algorithms like “sort” provided in the stl < algorithm> header.

        #67379
        Wheels-Of-FireWheels-Of-Fire
        Participant
          @grahamdearsley
          Forumite Points: 4

          I just read a rant on Quora by some bloke who said that C++ is useless for embedded systems and driver programming because it doesn’t support “malloc”.

          Well first off C++ supports ALL the functions in C stdlib.h but it renames it cstdlib to avoid confusion with the C++ standard library.

          Secondly, the C++ “new” function allocates arbitrary sized blocks of memory on the heap but it insists on being given a type.

          I may be missing something here but all data is made up of bytes so if I don’t know the type I need then can’t I just allocate a block of unsigned characters and then cast them to whatever type I like later ?

          #67382
          Ed PEd P
          Participant
            @edps
            Forumite Points: 39

            Never bothered using C++ for embedded systems as it used to have too much baggage with all its run-time aspects.  The other aspect of C++ that would cause me concern is garbage collection as this can be a vital requirement in small embedded systems. I’d probably just drop straight down to assembler for speed.

            Many such systems use Delphi (or its FOSS Lazarus) as it makes it very easy to use embedded assembler.

            If I had to use C++ then I would just use the good old C library function ‘sizeof’ which still seems to exist in C++.

            #67384
            Wheels-Of-FireWheels-Of-Fire
            Participant
              @grahamdearsley
              Forumite Points: 4

              http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2186r0.html

              C++ has offered support for an external garbage collector since 2008 but the above paper to the ISO committee proposes removing it.

              The sizeof() function is still alive and well and has been extended to support C++ types such as “class”.

              VC++ supports inline assembly for x86 CPU’s and linking to external modules for ARM and others.

              Even so, it is still possible to buy 8 bit micro controllers with only 4K of internal memory for code, ASM would be a must for them.

              #67386
              Wheels-Of-FireWheels-Of-Fire
              Participant
                @grahamdearsley
                Forumite Points: 4

                On a side note, C++0x turned out to be C++11 because it took 3 years longer than expected to approve 😁

                #67387
                Ed PEd P
                Participant
                  @edps
                  Forumite Points: 39

                  In the past (I cannot speak for today’s C++) Delphi had the huge advantage of an efficient RAD+widget support for the HID coupled with an easy to use inline assembler. Pity they had crap marketers who kept their sights on competing with the big iron world of database interfaces. Instead of being a huge fish in a growing pond they became also ran minnows against the likes of C++, Oracle etc. Delphi is still going strong and is pretty strong in cross-platform apps for pc,iOS and Android, but they still do not push the one area where they still have an advantage.

                  #67421
                  Wheels-Of-FireWheels-Of-Fire
                  Participant
                    @grahamdearsley
                    Forumite Points: 4

                    Hmm. Found another aspect of C++ that I wasn’t previously aware of, the Core Programming Guidelines.

                    The CPG sets out rules and guidelines for writing good code using modern C++ facilities and they are all given a reference number.

                    The CPG is not a part of the standard but it may as well be because it comes with its own Guide Standard library (gsl::) that provides functions to make following the guidelines easier (gsl::span is notable) and the gsl is included with all recent compilers.

                    The other thing to note is that the VC++ code analysis tool is based on CPG rules by default and it will return a rule reference number if it thinks your code breaks the rules.

                    #67423
                    Wheels-Of-FireWheels-Of-Fire
                    Participant
                      @grahamdearsley
                      Forumite Points: 4

                      “CppCoreGuidelines/gsl-intro.md at master · isocpp/CppCoreGuidelines · GitHub” https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/gsl-intro.md

                      More info about gsl:span above. It also turns out that made it into the C++20 standard library and its implementation makes use of the “byte” type that was introduced with C++17.

                      #67471
                      Ed PEd P
                      Participant
                        @edps
                        Forumite Points: 39

                        If you managed to move past Lambda expressions, you may be interested in using coroutines (and why you would even bother!)

                        https://www.scs.stanford.edu/~dm/blog/c++-coroutines.html

                         

                        #67476
                        Wheels-Of-FireWheels-Of-Fire
                        Participant
                          @grahamdearsley
                          Forumite Points: 4

                          Funny enough Ed.

                          I just took a break from my main two books to have a reread of Stroustrup’s “A Tour of C++”.

                          I just finished skimming the chapter on Concurrency and it is full of words like coroutine, future and promise but relating to separate threads rather than just separate functions.

                          If I ever do figure out what it all means ill let you know 😁

                          #67478
                          Ed PEd P
                          Participant
                            @edps
                            Forumite Points: 39

                            Reading the blog I referenced it strikes me that an awful lot of the recent language complexity of C++ is put in there not so much for performance but to pretty-up the code in an attempt to make the code more readable and hence easier to maintain.

                            Imo there is also a trade off between language complexity and application maintenance. Its all very well having a well documented system but not very helpful if only one of your programmers has all the necessary skills to understand it, and he/she has just gone on vacation!

                            #67484
                            Wheels-Of-FireWheels-Of-Fire
                            Participant
                              @grahamdearsley
                              Forumite Points: 4

                              I was thinking the same thing.

                              C with classes introduced nice concrete classes that enclosed things that belonged together into an object, you could use derived classes with inheritance if you wanted too.

                              C++ brought in constructors and destructors which help greatly in ensuring that a class frees all its resources when it goes out of scope. All part of what Stroustrup calls RAII and if used correctly it eliminates any need for a garbage collector because you don’t leave any garbage.

                              Next up was template classes which helps with writing generic classes, <vector> is a template class.

                              As far as I am concerned they could have stopped there !

                              #67496
                              Wheels-Of-FireWheels-Of-Fire
                              Participant
                                @grahamdearsley
                                Forumite Points: 4

                                I have come to notice something about ALL teach yourself C++ books, they are ALL mighty big on function and class declarations but tiny on definitions.

                                I understand that there is limited space in the book but you can’t play with a code fragment when most of it is missing.

                                Classes are the worst because they can have internal and external functions.

                                The definition of internal functions just gets replaced with “// definition goes here” and external definitions don’t get a mention.

                                #67557
                                Wheels-Of-FireWheels-Of-Fire
                                Participant
                                  @grahamdearsley
                                  Forumite Points: 4

                                  Just a note on class constructors, to remind me as much as anything else 😁

                                  ALL class data members are initialized by a comstructor, if you don’t provide ANY then the compiler will define synthesised default constructors. If you provide an initializer in class:

                                  int avar = 0;

                                  Then the default constructor will use that but if not it will use the default, no variables are left uninitialized.

                                  A thing to note is that if you supply even ONE constructor then you must supply ALL of them because defaults will no longer be generated.

                                  Default constructors do not appear in your source code but they will be there in the compiled code.

                                  #67561
                                  Wheels-Of-FireWheels-Of-Fire
                                  Participant
                                    @grahamdearsley
                                    Forumite Points: 4

                                    And a note on Destructors.

                                    If you dont’t supply a destructor then the compiler will synthesise a default destructor for you. Even if you use “new” to allocate an object on the heap but forget to use “delete” the default destructor will delete the object for you when the class goes out of scope. One reason why garbage collection is not required.

                                    If you wan’t an object to remain in memory after the class goes out of scope then you must declare it “static”, such objects are your own look out 😃

                                    #67573
                                    Wheels-Of-FireWheels-Of-Fire
                                    Participant
                                      @grahamdearsley
                                      Forumite Points: 4

                                      One more (for the moment 😁) note on constructors.

                                      The fact that you can provide in class initialisers is new to C++11 and if you provide them for all objects of built in type then you can use:

                                      class name () = default;

                                      That will generate a default constructor for the built in types even if you did supply constructors for other types.

                                      Another thing is that if one of your class data objects is its self a class type and that object has its own constructor then that will be used to initialise the object, no need to supply another one.

                                      #67581
                                      Ed PEd P
                                      Participant
                                        @edps
                                        Forumite Points: 39

                                        I knew I had a good reason for disliking C++; apparently Python is faster!

                                        Pdf link

                                        #67583
                                        Wheels-Of-FireWheels-Of-Fire
                                        Participant
                                          @grahamdearsley
                                          Forumite Points: 4

                                          Hmm. It seems to me that the only thing a degree in computer science qualifies you for is writing papers about computer science 😁

                                          But seriously, some types of sort are faster in Python 2 than they are in C++ prior to C++20 ?

                                          Im not going to lose any sleep 😂

                                          #67584
                                          Ed PEd P
                                          Participant
                                            @edps
                                            Forumite Points: 39

                                            Nor me, but it does at least rationalise my irrational viewpoint, which was I think brought about by a view that C++ had become far too bloated. I think I would have been very happy if they had frozen it at the Object C stage as I felt that the owners of C++ were guilty of changing things just to stay in their jobs.

                                          Viewing 20 posts - 181 through 200 (of 259 total)
                                          • You must be logged in to reply to this topic.