October 31, 2018 at 8:11 pm #27773ParticipantWheels-Of-Fire@grahamdearsley
<p style=”text-align: right;”>Can we put this topic up please boss. In tech ?</p>
September 27, 2020 at 11:48 am #62245
I take back my comments, poxy C++ makes it very hard to use raw pointers.
You may have to use ‘friend’September 27, 2020 at 12:28 pm #62247
Open C++ book.
Read first paragraph.
Lie down in darkened room.September 27, 2020 at 2:18 pm #62249
😃Oh no. This is the book I was looking forSeptember 27, 2020 at 2:24 pm #62251
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.September 27, 2020 at 4:38 pm #62253
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’.September 27, 2020 at 9:39 pm #62255
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.September 29, 2020 at 12:42 pm #62277
I think i should also point out that if you had a pointer to an expanded Vector it won’t be validSeptember 29, 2020 at 5:44 pm #62281
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.October 3, 2020 at 1:09 pm #62376
Well thats interesting but if you expand a vector its array of pointers must move it really must to stay contiguosOctober 3, 2020 at 1:19 pm #62378
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 timeOctober 7, 2020 at 9:27 pm #62450
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.October 10, 2020 at 12:36 am #62527
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 😁October 10, 2020 at 11:35 am #62534
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.October 10, 2020 at 3:23 pm #62539
You do realise I was joking don’t you Dave ?October 10, 2020 at 7:25 pm #62543
LOLOctober 12, 2020 at 1:11 am #62549
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 &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.October 12, 2020 at 1:21 am #62551
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 !October 12, 2020 at 7:12 am #62554
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.October 12, 2020 at 12:12 pm #62557
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.October 12, 2020 at 12:19 pm #62559
There are 2 ways of escaping ring 3 and getting into ring 0, software interrupt and syscall, and Windows traps them all.
- You must be logged in to reply to this topic.