Anonymous
an overflow of unsigned is not UB
Anonymous
Anonymous
It is.
It is not
Mat
UINT64_MAX - 2
UINT64_MIN - 2 is equals to... ?
Anonymous
UINT64_MAX - 2
UINT64_MIN - 2 is equals to... what ? How does the typecasting works here? Can anyone explain?
Anonymous
Is the result unsigned too?
Anonymous
I mean unsigned -2 is unsigned?
Anonymous
there is no -2 in the expression
Anonymous
I lied
You lied or made a mistake?
Anonymous
2 casts to 2u
Anonymous
ya
Anonymous
You lied or made a mistake?
The second one led to the first one
Anonymous
So, in
Anonymous
"i<a.length()-2" the "2" was made unsigned
Mat
Anonymous
So, does, "i" gets casted to unsigned
Anonymous
too?
Anonymous
Yes
Anonymous
So considering that a.length() is 1 then what is the result of a.length() -2?
Anonymous
https://stackoverflow.com/questions/18195715/why-is-unsigned-integer-overflow-defined-behavior-but-signed-integer-overflow-is/18195756
Anonymous
Unsinged overflow is not an UB
Anonymous
hmm YOu were right. I
Anonymous
Anonymous
Simply, the max possible value of std::size_t minus 1
Anonymous
Ty
You're welcome
Anonymous
Anonymous
Why max and not something else?
Because overflow happens
Anonymous
std::numeric_limits<std::size_t>::max() - 1
It is std::numeric_limits<std::size_t>::max() - 2
Anonymous
it is not
I wrote a.length()-2
Anonymous
Because overflow happens
so a.length() -2 = -1 and -1 is not unsigned so, it goes back to the max?
Anonymous
Yeah, probably it is just max
Anonymous
So, my condition that
Anonymous
i<a.length()-2
Anonymous
goes till max
Anonymous
http://ideone.com/zdbZF3
Anonymous
Anonymous
http://ideone.com/zdbZF3
this is the proof
Anonymous
this is the proof
Thanx for helping out.
Anonymous
https://docs.microsoft.com/en-us/cpp/cpp/type-conversions-and-type-safety-modern-cpp?view=vs-2019
Anonymous
Learn this
Anonymous
https://stackoverflow.com/questions/12396132/c-implicit-type-conversion
Anonymous
So, what is the right way to make a.length() -2 to -1 and not max
Anonymous
/notes
Anonymous
@unterumarmung (int)a.length() -2 Is this the right way?
Anonymous
Can u be sure here? Bcz. I'll be needing that many times in the future.
Anonymous
I'm assuming that the length of string a doesn't exceed the int limit.
Anonymous
Why?
Anonymous
Because signed overflow is an UB
Anonymous
Thanks a lot
Anonymous
Because signed overflow is an UB
But, suppose that a.length() value is withing the int limits. Then that shouldn't be a UB.
Anonymous
It will
Anonymous
Because singed limit is less than unsigned one
Anonymous
But for your purposes it can be ok
Anonymous
But, I'm typecasting something whose value is within the range of what I'm typecasting into.
Anonymous
Then that UB shouldn't occur
Anonymous
It shouldn't
Anonymous
Does anyone here use VSCode ?
Anonymous
I want to ask if I can debug my code while taking inputs using cin?
Anonymous
Use gdb debugger.
Anonymous
Anyone here from Prestige college Indore?
Nomid Íkorni-Sciurus
Nomid Íkorni-Sciurus
Why is flycheck yelling at me?
Nomid Íkorni-Sciurus
what is wrong with that declaration?
Nomid Íkorni-Sciurus
Oh. In C you just can't return a function. Solved by returning its pointer.
Anonymous
Is there a way to find out how much memory did my program occupied while running?
Nomid Íkorni-Sciurus
Nomid Íkorni-Sciurus
because for example, Windows and Linux kernels have different approaches for memory allocation
Anonymous
Just as we can find the time so can we find the memory occupied?
Nomid Íkorni-Sciurus
Just as we can find the time so can we find the memory occupied?
wait... by "we can find the time" you mean the... time { ... } command ?
I_Interface
Is there a way to find out how much memory did my program occupied while running?
Try for Visual Studio: while debugging >> Diagnostic tools