Asad
Hey guys, it is written on "A Tour of C++" that this book is for those who have coded before. Can complete beginners also learn C++ programming language from it?
Rosita
Mihail
You don't know that, it's undefined behavior
Technically yes, which is why I said that you shouldn't assume in the message below (but you clearly decide to skip reading that one), but you could get weird results for operations which include a read and a store (for example an increment) for an operation which is just a store you can't get a different result
olli
2. "Two expression evaluations conflict if one of them modifies a memory location ([intro.memory]) and the other one reads or modifies the same memory location." 21. [...] Two actions are potentially concurrent if - they are performed by different threads, [...] The execution of a program contains a data race if it contains two potentially concurrent conflicting actions, at least one of which is not atomic, and neither happens before the other [...]. Any such data race results in undefined behavior. http://eel.is/c++draft/intro.races#2 http://eel.is/c++draft/intro.races#21
shoker
how do i type in the or operator?
olli
how do i type in the or operator?
logical-or || bitwise-or |
shoker
what symbols are these on the keyboard
Wim
the pipe character?
olli
what symbols are these on the keyboard
might depend on your locale. On intl keyboards they look like this |
Anonymous
/report
Dima
What
Dima
klimi
What
exactly
Dima
that moron just added me into his group
Dima
how puny
klimi
Whew
MᏫᎻᎯᎷᎷᎬᎠ
Why we just not prevent the error of "out of the index bound" by using the % arithmetic operator Like if we have an array of size 10 And the user asked for the 15th element We just write arr[15%10]
MᏫᎻᎯᎷᎷᎬᎠ
Better than throwing the processor to read a non-related data, right?!
MᏫᎻᎯᎷᎷᎬᎠ
Anyway Eventually you'll have to go the long way Cuz a good program causes exceptions in this type of operations(with the need of if statement)
MᏫᎻᎯᎷᎷᎬᎠ
a comparison is faster
If (15>10)??!!
BinaryByter
division is a long operation
BinaryByter
BinaryByter
only if it is, you do the modulo
BinaryByter
but why would you want to do that?
BinaryByter
Its still additional work
BinaryByter
think before posting
MᏫᎻᎯᎷᎷᎬᎠ
But the comparison will make you worry about another things like What to do in case of errors But here you'll definitely provide the user the request
BinaryByter
Rust does it - and it doesnt really help too much
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
It's sooo obviouse Why would I need to provide the results?!!
MᏫᎻᎯᎷᎷᎬᎠ
what?
That's what you asked
BinaryByter
Why you'd need that?
MᏫᎻᎯᎷᎷᎬᎠ
Need what?!
BinaryByter
I mean - if you do the modulo thing, you end up with data that doesnt help you
BinaryByter
if you do the exception you might as well cause a sigsev
BinaryByter
read what I said
MᏫᎻᎯᎷᎷᎬᎠ
The right results are data that don't help me?!!
BinaryByter
The right results are data that don't help me?!!
you want to do the modulo thing in order to avoid sigsevs, right?
BinaryByter
Well if I have an out-of-bounds, the data that I get by modulo will be unrelated
MᏫᎻᎯᎷᎷᎬᎠ
And worry about the headache
BinaryByter
in a sorting algorithm, it would cause data to be duplicated
BinaryByter
which would be even more fatal since you never find out
BinaryByter
+ again: division is slow
MᏫᎻᎯᎷᎷᎬᎠ
103737636%10 Is certainly under 10
BinaryByter
BinaryByter
again: you don't need such things
BinaryByter
any check is slower than none
BinaryByter
How?! Like?!
imagine that instead of getting an out of bounds exception, I just get the data from the start again
olli
a comparison is faster
is not always true..
BinaryByter
is not always true..
subtraction is slower than division?
BinaryByter
🤨
Daniele°
Exceptions yeah
http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html
olli
subtraction is slower than division?
depending on your value a division is/can be a shift (for divisors 2^n) hence not always
MᏫᎻᎯᎷᎷᎬᎠ
imagine that instead of getting an out of bounds exception, I just get the data from the start again
Hmmm Maybe that would be a headache But we can in some cases use the module operator
BinaryByter
BinaryByter
+ that only works with div by 2^n
MᏫᎻᎯᎷᎷᎬᎠ
olli
there is no generalization.. do the benchmarks
BinaryByter
we are talking about the modulo part of the division 😉
how do you get a modulo by shifting? @ollirz @Drazzy ?
MᏫᎻᎯᎷᎷᎬᎠ
BinaryByter
You mean the reminder?!
yes, thats a modulo
MᏫᎻᎯᎷᎷᎬᎠ
olli
how do you get a modulo by shifting? @ollirz @Drazzy ?
look at the output of compilers when modulo 2^n
BinaryByter
^
No, divisions are slower because they are done by loop