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 - 81 through 100 (of 118 total)
  • Author
    Replies
  • #62245
    Participant
    Ed P
    @edps
    Forumite Points: 16,565

    I take back my comments, poxy C++ makes it very hard to use raw pointers.

    You may have to use ‘friend’

    link

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

    Open C++ book.

    Read first paragraph.

    Goto End.

    Close book.

    Lie down in darkened room.

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

    😃Oh no. This is the book I was looking for

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

    it is a primer like it says because it misses out some of the more advanced stuff but if goes into great detail on what it does cover.

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

    Researching your comments I found that I am twenty+ years out of date! C++ reflects the design of modern OSs where the hardware lives at Ring 0 and has reflections onto Ring 3 but keeps the real stuff protected on Ring 0. As a result C++ prevents you writing stuff for an Atari or any other DMA system even if it is living in a vm or emulator.

    As an aside I accidentally found this site which (ignoring protected mode) shows how arbitrary memory addressing can be carried out in 22 different ‘languages’. :yahoo:

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

    well yes sort of

    WIndows gives user programs a user and a kernal stack. Every time a user program calls a Windows function it changes into kernal mode.

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

    I think i should also point out that if you had a pointer to an expanded Vector it won’t be valid

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

    I think i should also point out that if you had a pointer to an expanded Vector it won’t be valid

    This link gives a useful understanding of vectors in C++. As you can assign things dynamically to a vector it isn’t too surprising that it barfs if you try to point at expanded elements as it would be pretty easy to generate variables that pointed at thin air.

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

    Well thats interesting but if you expand a vector its array of pointers must move it really must to stay contiguos

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

    oh thats why it expands more than needed when it moves, gives extra capacity so it wont have to  to move again so soon. In fact they normally expand X2 every time

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

    I haven’t tested this because I only just read it but…

    I really should have noticed before but I thought I knew about References from C.

    C++ try’s to stay away from pointers with its Reference feature. You can create a reference to an object and the new Reference object will basically BE the original object because it will always point to the original objects Value, what you do to one you do to the other.

    You can use this to pass an object by reference to a function without creating a pointer and then dereferencing it in the function.

     

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

    Referring back to Dave’s comment about C++ books.

    Drop my new book on foot

    Go to Hospital

    Get plastered up !

    This book is 1023 pages, about 3 inches thick and seriously heavy 😁

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

    Wow, I saw a few unusual injuries when I spent the summer in hospital but that’s a new one on me.

    The “best” one was an old boy sat in his deckchair when the Mrs tells him to move as she wants to put the washing out. It’s only a foot or two so he doesn’t stand up and move it, he tries to shuffle it along. Chair collapses, minus one finger!

    95% were like me, motorbikes, next favourite chainsaws and fingers followed by hover mowers and toes. Very few car accidents but they were all very nasty.

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

    You do realise I was joking don’t you Dave ?

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

    LOL

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

    I said above that a reference is an object but in fact it isn’t. A reference doesn’t have a memory address of its own (though it must be in memory somewhere) , it uses the address of the object it points to so it is in fact an alias. As a result you can’t have a pointer to a reference (there is no address to point to but you can change its value which will change the value of the object it refers to. The syntax for creating a reference is.

    int i=100

    int &r = i

    r is a reference to i and its type must be the same, ie int in this case. We are using & yet again ! but this time in a declaration so its meaning is different from dereferencing a pointer.

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

    One more thing I finally understand. My book kept going on about compound types 🤨. Well a reference is a compound type because it is both the base type of the object it points to, say int, and a reference, same with a pointer. Simple as that !

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

    I think if you know assembler it is a whole lot easier to understand what sits under the ‘simplifying’ assignments of C++ and its p-code engine.

    I find C++ too restrictive and klunky to go back to it. Mind you I find Python equally klunky and annoying because of its use of spaces as delimiters and the way it also unnecessarily wraps around constructs with obscurity. I guess though that this is what you get when you swap bare-metal coding for the protected mode of modern bytecode languages that do not directly interface with the hardware but instead run on a virtual protected computer. Python at least makes up for this by a huge repository of code wrappers. In fact if you want to use AI without making your eyes bleed then Python is pretty much de rigeur.

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

    Well I do know a fair amount of x86 assembly and a whole lot of 6502 😁. Programming x86 in Real mode is fairly simple but if you switch to Protected mode it gets a whole lot more complicated. The best idea is to get hold of a micro kernel that will set up the memory tables and handle the switch to protected mode for you but even then you have a bewildering array of new registers to deal with.

    If you want to write asm programs that run on a modern OS like Windows then things get even more complicated because you have to deal with its memory model too.

    On the the other hand, a modern language like C++ will handle that for you. You can’t get that close to the metal anyway because your user programs are in CPU ring 3 and it just isn’t allowed.

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

    There are 2 ways of escaping ring 3 and getting into ring 0, software interrupt and syscall, and Windows traps them all.

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