@grahamdearsley
Forum Replies Created
-
AuthorPosts
-
My book is being very careful to point out the difference between a parameter and and argument. When you declare a function you supply a list of the parameters it takes and when you call a function you supply a list of arguments with the same type as the parameters.
I don’t really see why the book is making such a big thing about the distinction between the two.
I also see that the author of the article isn’t keen on the stupid operator overloading of the & symbol either 😁
Ah yes there is a reason and in fact my C++ book gets round to it a few pages further on.
If you are passing a large structure to a function instead of a simple variable then passing a const reference will negate the need to create a copy to pass, as would be done if you passed by value.
Another thing the book gets into later is top level and low level constants and where the constantness of a top level constant may be ignored !
I mentioned before that my book keeps banding on about “const” objects and now i’m re reading it there is still a situation I don’t see the point to.
I can pass a reference to a function as follows.
Void funct(int &val)
{ val= 10}
int v=0
void funct(int &v)
The result of the above will set the value of v to 10.
Fair enough.
The thing is though I can also pass a const reference so the function can’t change its value.
void funct(const int &val)
Can anyone tell me what the point of that is ? Objects are already passed by value by default so you can’t change the value of the argument, surely the point of passing by reference is so you CAN change it ?
My i7 990X could do a pretty good job of boiling a kettle, 130W without the hefty over clock i’m using 🤪.
The Passmark multithread scores are almost identical too at the stock speed.
Speaking of the i5 10th Gen (which Dave did 😃), its Amazon deal day today so I ordered a Surface Pro 7 for £659.
Core i5 1035G4, 8GB DDR4, 128 GB SSD.
I ordered the type cover as well and it should arrive on tuesday next week. I really brought it to compile my C++ programming efforts quickly but it looks like the iris plus graphics arn’t too bad either.
Wow a 32MB BIOS. My X58 mobo has 2x2MB flash for the BIOS which enabled it to have a basic UEFI update where as other X58 boards with 1MB could not. But 32MB !
In case it’s not obvious, i’m going through my book again from the beginning and picking out the bits I missed the first time.
Expect a lot more 😁
Another “Helpful” C++ feature that is bound to lead to confusion, this time with vectors.
It is possible to initialize a vector in a number of ways and from C++ 11 that includes a list enclosed in curly braces.
vector<int> V1 {10,20}
That is a vector with two elements of 10 and 20.
You can also initialize a vector with a number of default elements using brackets.
vector<string> V1 (10, “hi”)
That vector has 10 elements and they all have the value “hi”.
So far so good.
However if you attempt to list initialize a vector with braces but supply the wrong type C++ will “helpfully” attempt a value initialization instead.
vector<string> V1 {10, “hi”}
This gets you a vector of 10 hi’s again even though you used curly braces.
It is going to confuse me if no one else 😆
There are 2 ways of escaping ring 3 and getting into ring 0, software interrupt and syscall, and Windows traps them all.
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.
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 !
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.
You do realise I was joking don’t you Dave ?
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 😁
Can’t they use sonic shock treatment to break up the stones these days ?
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.
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
Well thats interesting but if you expand a vector its array of pointers must move it really must to stay contiguos
I think i should also point out that if you had a pointer to an expanded Vector it won’t be valid
-
AuthorPosts
