Forumite

C++ Programming

  • Creator
    Topic
  • #27773
    Participant
    Wheels-Of-Fire
    @grahamdearsley

    <p style=”text-align: right;”>Can we put this topic up please boss. In tech ?</p>

Viewing 20 replies - 61 through 80 (of 118 total)
  • Author
    Replies
  • #62043
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    Well I’m half way through my new programming book and so far it has been very good, but I can’t let it get away without a couple of niggles 😁

    At the start of the book they say they are going to be teaching the latest C++ standard from the off, where a new feature is in every way better than an old one they will only cover the new one. Fair enough but then they spend a lot of time covering old features that you will only need if you want to use your new code with existing old code. I think that should have been covered in a separate chapter because it breaks up the flow of things.

    The other niggle is that I think they over complicate some things too early. For instance, from the very start they say it is best to pass arguments that a function won’t change as Const, then they describe at length the restrictions that will cause. Well it is good practice but I think it is a bit over the top for a C++ Primer book.

    Comments are welcome on the above πŸ˜ƒ

    #62045
    Participant
    Dave Rice
    @ricedg
    Forumite Points: 9,287

    If it’s not spaghetti code I’m lost. Seriously I used to enjoy coding when I could freestyle it, I don’t have the patience to structure things properly. That’s not to say my coding was a total mess, I learned early that I needed to comment almost every line and try and keep it neat because when you come back to something you can never work out what’s going on :wacko:

    If I could get my old Atari 800 back with the basic and assembler cartridges I think I would have a play again. Oh and Page 6 magazine.

    #62047
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    http://www.virtualdub.org/altirra.html

    If you really wan’t to play around with Atari 8 bits then emulation is probably your best bet. Altirra, linked to above , is meant to be the best but I use Atari Win800.

    Once you have your emulator set up then head on over to Atarimania for all the software and books/mags ever written. You’ll be playing Star Raiders again in no time πŸ˜ƒ

    The best thing about programming on an emulator is that you can have a hard drive as device H: and save directly into a folder on your PC.

    I hope you give it a try because then you can have a go of the Sudoku solver program I just wrote in Atari BASIC, posted on the Atariage 8 bit forum 😁

    #62066
    Participant
    Dave Rice
    @ricedg
    Forumite Points: 9,287

    Excellent, thanks for the link.

    #62068
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    My #1 Apple-loving son really learned to program with STOS Basic for the C64 as that gave him the ability to manipulate sprites and have animation in his games. Unfortunately imo there is nothing quite so inspiring in children’s programming languages today. Scratch appears to be passably okay, but only if you like fiddling with little pseudo-building blocks. Far too much overhead for my taste.

    #62070
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    I don’t know much about Scratch but Atari BASIC would be considered low level compared to some of the fluff that’s out there today.

    Now if we all have our emulators set up then a really good demo of what the old 8 bit can do is Numen (Single disk).

    This is an auto boot image so you need to run it from the boot image option under file in Altirra and then hit enter to start.

    #62136
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    My new book has been telling me more about Vectors and C++ style strings.

    The elements in a Vector must be stored continuosly in memory so that they can be accessed by an index number. If you initialize a vector with an initial number of elements using square brackets, “[10]” say, or a list of initial elements then the vector will be allocated enough memory for them ONLY to start with.

    If you use the push_back function to add another element to the end of the list then more memory will need to be allocated. To make sure that the memory remains contiguous the Vector function needs to assign a new bigger block and then copy the existing elements into that before deleting the originals. The Vector function ensures that the Vector name now points to the new block. This time round the Vector function assigns more memory than the new Vector will need and the amount is implementation specific. You can use the Capacity function in Vector to find out how much extra you have.

    The other point to note is that the elements in a Vector are only pointers or “vectors” to the actual data the Vector holds so that data does not move when a Vector is expanded, that and the extra capacity makes expanding Vectors quick.

    C++ std library strings work in a similar way but their elements actually do hold the charachte data.

    #62175
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    If you like playing with C++, you may like to try Swift as this will enable you to build cross-platform GUI Apps for Apple, Android, Linux and Windows.

    #62187
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    I may have a look at that later but at the moment I am trying my best to stick to just plain C++, Visual Studio does not make that easy though because Microsoft would really rather I used C# under the .NET framework to produce managed code. In fact they would really rather I wrote Universal app platform apps but it ain’t happening any time soon.

    #62205
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    More interesting info about Struct’s in my new book. In most ways C++ treats a Struct exactly the same as a Class. The only difference is that Struct’s don’t support inheritance. You can have a function in your Struct, no problem.You can even have a local Class in your Struct (you will have to pass any arguments from within the Struct).

    #62207
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    You can also have pointers to functions andΒ  double pointers (pointers to pointers) in your structure and these can when unwound point to other structures which in theory could even have double pointers pointing back at the calling structure. You can tangle your brains completely if you do this!

    C/C++ enables you to do all sorts of crazy things which is why M$ pushes managed code.

    #62209
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    Well you could do that but I think that inheritance has mostly been introduced to make such things unnecessary, meant to keep your thinking on the straight and narrow.

    I don’t really know though because I only just started the chapter on inheritance and so far its as clear as mud 😁

    #62211
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    I intended to skim the whole book just to get a flavour of whats in it and then start again at the beginning, doing the exercises, but I got sucked in so im READING the book without doing the exercises πŸ˜„

    When I get to the end I will have to start again and do it properly.

    #62227
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    I am going to need to go again with the exercises to make things stick. Remembering the syntax is the main thing and only practice will do it.

    I know when I want to pass an object by reference or by value but the *’s or &’s are a pain. Then we get && and other such things.

    Then we find C++ can pass an object AS a reference to another object instead of using a pointer, anything you do to the reference also happens to the original object .

    Like I said, some practice required.

    #62231
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    And then we get “range” FOR loops. I know what they do but I forget where the iterator comes from. Practice, practce,practice πŸ˜†

    #62233
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    Based on my old C experience you really need to crack pointers and addresses as they underpin arrays, strings etc, but probably as important is the need to correctly instantiate and range check anything you use otherwise you finish up with pointers that point at thin air and null addresses.

    Once you crack that then comes the real pain of making sure that you have already set aside memory for these objects (malloc etc.), and of course freeing it (garbage collection). This is the area where you can generate really unsafe programs e.g. memory overflow, use after free, corrupted double pointers,Β  etc.

    Just when you think you have cracked it all comes the problem of error trapping i/o. This becomes a very hard slog and only a very few programmers manage to write large completely ‘safe’ programs or routines. Bad programs can result in users blaming the OS for any security lapses (think of the ordure that Flash caused for years) and this is really why M$ pushed C# (though to be fair there are competitive ‘safe’ programming languages that are also a step or two away from the machine code that compiled C++ produces. e.g. Ruby, Python etc).

    #62235
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    C++ tries to keep me away from pointers with its references. I can just pass a reference to an object, it is almost the REAL object, if I change it I change the memory the original points to.

    Exception handling is in 2 chapters time πŸ˜ƒ

    #62237
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    REALLYΒ  good book

    #62241
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,149

    Still can’t match the hardware access I get in Atari BASIC. Can Peek or Poke from there πŸ˜ƒ

    #62243
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    Take the addresses of your peek and poke (say Pe and Po).

    To peek just set a pointer to Pe (say pPe) then :

    Pe = 0xCEff44Β  /* address in hex

    void * pPe = (void *)Pe

    if it is a char then use char* instead of void for other types of pointers such as struct etc

    then just read the value pointed at by *pPe

    printf(“value of peek = %d\n”, *pPe);

    Poke is pretty much the converse look at this for more.

    I recommend looking at C for obsolete uses such as peek and poke as they were deprecated about the time that C++ was released.

     

     

Viewing 20 replies - 61 through 80 (of 118 total)
  • You must be logged in to reply to this topic.