Viewing 19 posts - 241 through 259 (of 259 total)
  • Author
    Posts
  • #68162
    Wheels-Of-FireWheels-Of-Fire
    Participant
      @grahamdearsley
      Forumite Points: 4

      And in case you didn’t already know, size_t is an implimentation specific type that is defined on a per system basis, mostly based on the word size of the hardware, its there for portability reasons.

      Many of the std library functions return objects of type size_t, in the previous example the <string> member function “size()” returns size_t type.

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

        I got around my problem of class instances needing a unique name.

        A class instance DOES need a unique name and it can only be assigned by a literal but the members of a vector only have a type and an index.

        I can have class called “sample” and an instance of it called “sample1”, I can then have a vector called “test” that contains objects of type “sample”. I can now push_back “sample1” onto “test”, change the contents of “sample1″, and push_back again.

        I can do the above as many times as I like and then access the class objects by their vector index number, like so:

        class sample

        {int value1 = 10};

        vector<sample> test;

        sample sample1;

        test.push_back (sample1);

        sample1.value1 = 20;

        test.push_back (sample1);

        cout << test[0].value1<<” “<<test[1].value1;

        Prints 10 20 and that’s just what I want 😁

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

          Another nugget from C++11, the list initialised function return value.

          If a functions return type is a class type like <vector> then I can return a braced list of values, like so:

          vector<string> example()

          {

          return{string1, string2, string2}

          }

          The returned <vector> is initialised with however many strings I return so I can return ANY number.

          Suppose it could come in handy one day 😀

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

            A group of associated values is essentially a ‘tuple’. In Python for example this would be used for parsing things like csv tables, or many other collections in standard format  such as XML, RSS, or JSON data structures.  I first came across tuples in Visicalc (the spreadsheet program that was copied by Lotus 123, Excel etc.).

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

              Did you know that Visicalc was avaliable for the Atari 800, almost as soon as the computer was released ?

              Wordstar was avaliable too, and yet still almost no one brought “An Atari” for their office 😁

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

                Another C++11 type is the… tuple !

                A tuple is a template type so the syntax includes the extra type data in angle brackets like so:

                tuple<int, string, double> example

                I can also follow the declaration with a braced initialiser list if I like.

                A tuple can contain almost any type but once it is declared its size is fixed.

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

                  Unfortunately my old company had committed to Apple IIs by that time. We were cheapskates and would have had no problem in trying Atari as that period was one of getting people to become comfortable with computers (lunch hours were spent playing Star Trek etc.). Later on we even tried the Sinclair QL! – That could have been a great business machine if only Sinclair had not gone for their silly tape drive. In all other respects the business software suite was well ahead of its time.

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

                    Ah yes, the micro drive, complete with the extra stretch tape 😁

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

                      Off topic again but the Atari tape system was quite unusual too.

                      The datacorder was analogue/digital. The Poky sound chip sent analogue signals out on a dedicated wire, to be recorded, but the return signal was first converted into digital and then sent back over the serial i/o bus.

                      The tape file system was unusual too, because it had one that it didn’t use. If you named a tape file then you had to load it with that name but no name was just as good. I think they may have been considering something like the micro drive but in the end the computer only got control over play/stop, not ff/rw that would have been needed.

                      Another thing was you could boot the computer from tape, that was unusual because most other micro’s couldn’t boot off anything.

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

                        most other micro’s couldn’t boot off anything.

                        Not strictly true.

                        In 1978 the Apple II was using floppy disks well before the Atari 400 was even launched! However, like all modern PCs the bootloader was in ROM and after some checks it executed whatever was in the first couple of tracks of the floppy.

                        I’d guess that your Atari actually booted from ROM then loaded its tape system for a second stage boot.

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

                          Just like a PC (only before it) the Atari’s had their boot loader in ROM. The normal boot order was to check for a  bootable cartridge signature first and to see if it also required disk support, if so pass control to the cartridge. Disk support was normally DOS for a language cartridge.

                          If no cartridge then check if the option key on the keyboard is pressed, if not then attempt a disk boot, if so then attempt a cassette boot.

                          A disk boot loaded the boot sector (sector 0) into memory and checked its signature before executing it, as with PC the boot code loaded anything else.

                          A cassette boot just loaded the next file on the tapes header and checked that it was bootable before loading the rest of the file at the headers load address and executing it.

                          If there was nothing to boot from then the early machines dumped you into memo pad mode but the later machines loaded the built in BASIC.

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

                            https://en.m.wikipedia.org/wiki/Shepardson_Microsystems

                            You may like the above Wiki Ed, shows that the Apple II and the Atari 8 bits had something in common.

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

                              I was just looking at someone’s question on Quara and he was asking how to construct an ordered multilinked list in C.

                              The answer is to design list nodes that have more than one pointer to the next node in a list, each data member of a node will have its own pointer so you effectively create a list for each searchable item.

                              I thought that this would be a bit of a faff because you would have to design your own srtuct with malloc and raw pointers to make it work. Then I realised that ALL linked lists in C were going to be a bit of a faff  because it doesn’t have a standard list type.

                              C++ has list and forward_list types so I am spoilt unless I need a multilinked list 😁

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

                                It actually wasn’t that bad in C as it was just a question of plagiarising the standard code that others had written – this is a good example : https://www.edureka.co/blog/linked-list-in-c/

                                The main value of dealing with things at low level is the ease of modifying the code to do things like doubly linked lists, and all the other forms such as circular lists, stacks, hash links, block chain where the links are encrypted etc. Of course all these can be done in C++ but that adds a layer of obfuscation  where you do not really know what is happening due to all the safe programming overhead.

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

                                  This one’s not C++ exclusive but I thought i’d put it here.

                                  I had been wondering how Address Space Load Randomisation could work when code wasn’t written to be relocatable, so I looked it up.

                                  The first thing to note is that Windows executable images are stored in Portable Executable format and PE files start with a header.

                                  As far as ASLR is concerned there are 3 items in the PE header that matter, Dynamic Load, Preferred base address and a relocation table.

                                  If Dynamic load is not set then an image is loaded at its Preferred base address, there is no ASLR. If Dynamic load is set then an offset is calculated and the image is loaded at the preferred address plus the offset. In 64 bit windows there are 256 possible offsets and they will all be within 16MB of the preferred address.

                                  Programmes are compiled assuming that the preferred address is where they will be loaded so any instructions that use an absolute address will be wrong if ASLR is in effect.

                                  To get around the problem, If Dynamic Load is set then the Linker generates a .reloc file that contains the addresses of all the instructions that have absolute addresses.

                                  When the Windows Loader loads a PE file with Dynamic Load set it loads the image at its new random address and then looks at the addresses in the .reloc file, it then adds the offset to the addresses it finds at those addresses so they are now “fixed up”.

                                  I nearly forgot to mention why you would want ASLR in the first place, its so that malicious code can’t jump to a fixed point in an image because that image will be in a different place almost every time it loads.

                                   

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

                                    I have been looking into C++ move semantics and rvalue references. First of all this

                                    int a=10;

                                    I can get a reference to “a” with &a, it is an lvalue, but I can’t get a reference to 10 because it is a literal and therefore an rvalue.

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

                                      As part of Microsoft’s push to make the console more Linux like they have reintroduced support for control codes, last seen in DOS with the ANSI driver installed.

                                      They are calling it ” Console Virtual Terminal Sequences” and they have to be enabled before you can use them. Below is some C++ (if swap cout for printf then its C) that enables Terminal Sequences safely and uses a code to move the cursor.

                                      #include<iostream>
                                      #include<wchar.h>
                                      #include<windows.h>
                                      #include<conio.h>

                                      using namespace std;

                                      int main()
                                      {

                                      HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

                                      if (hOut == INVALID_HANDLE_VALUE)
                                      {
                                      return false;
                                      }

                                      HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);

                                      if (hIn == INVALID_HANDLE_VALUE)
                                      {
                                      return false;
                                      }

                                      DWORD dwOriginalOutMode = 0;
                                      DWORD dwOriginalInMode = 0;

                                      if (!GetConsoleMode(hOut, &dwOriginalOutMode))
                                      {
                                      return false;
                                      }

                                      if (!GetConsoleMode(hIn, &dwOriginalInMode))
                                      {
                                      return false;
                                      }

                                      DWORD dwRequestedOutModes = ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
                                      DWORD dwRequestedInModes = ENABLE_VIRTUAL_TERMINAL_INPUT;

                                      DWORD dwOutMode = dwOriginalOutMode | dwRequestedOutModes;

                                      if (!SetConsoleMode(hOut, dwOutMode))
                                      {
                                      return -1;
                                      }

                                      DWORD dwInMode = dwOriginalInMode | ENABLE_VIRTUAL_TERMINAL_INPUT;

                                      if (!SetConsoleMode(hIn, dwInMode))
                                      {
                                      return -1;
                                      }

                                      cout << “blink”;

                                      cout << “\x1B[10;20fHello”;

                                      cout << “\x1B[11;20fWorld” << endl;
                                      }

                                      You don’t actually need to #include <wchr.h> or <conio.h> but my longer test program uses them.

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

                                        I should have mentioned that the newish Windows Terminal has control codes enabled as standard (if you haven’t got it already its on the Windows store) plus lots of other stuff.

                                        I haven’t yet figured out how to make my compiled programs launch in Terminal though 🙄

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

                                          I have been teaching myself  Microsoft Foundation Classes from the book “Programming Windows With MFC” for the past month or so. That is still the book to have but it is a bit old, it’s from 1999 and it’s aimed at Visual C++ 6.0. It took me until the beginning of the week to get any of the sample code to work with Visual Studio 2022 but now I have finished my first project based on code from the book, at least I think I have.

                                          it’s a very simple image editor with only one function, it turns colour images into grey scale. I have posted a link below with the source code and a stand alone .EXE (it needs no installing) and a sample bitmap of my friend and her daughter.

                                          https://1drv.ms/u/s!ApY7Ke0brhrmhIE-kM6Q-4E_OaVWmg?e=PY6fxE

                                          Comments from anyone who can load VS solutions would be welcome, but anyone can try the EXE, I think, comments about that would be welcome too 🙂

                                           

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