As always, I managed to make a mistake in the video. 🤷 In the code snippets that we debug, it should read **numbers.size() - 1UL** instead of just **numbers.size()**. I've changed the slides in the repository, but cannot change the video. The good part is that the code there was buggy anyway, so I hope the damage is contained. Apart from that, do you use a debugger or the print statements? 😉 Why? Please comment below!
@Fabian-jw4bw2 жыл бұрын
When coding in java with IntelliJ I always use the debugger, since it is really easy and inbound. Unfortunately, the C++ pendant from jetbrains (clion) is not available as freeware and I‘m not used to vscode.
@princepatel_channel2 жыл бұрын
always - print statements
@ramcharanthota10162 жыл бұрын
I used to print statements before. But, writing and deleting print statements is kind of annoying.So, I started using debugging tools though it is bit hard to get used to it initially.
@chrislee12992 жыл бұрын
I mostly use print statement because I feel it is more interactive to my code
@princepatel_channel2 жыл бұрын
thanks for introducing cerr. A new way of print statements.
@CodeForYourself2 жыл бұрын
Well technically we already talked about it in the streams video, but I'll take the "thanks" 😉
@andreibaraian88 Жыл бұрын
The output of the print statements does not seem alright. Since the size of the vector is 3 and initially i will be 3, it means that the first access to numbers[i] will access memory outside of the vector. Shouldn't the loop start from numbers.size() - 1? Then, of course, the error with the unsigned integer will happen, but that is a bit later. Was that the intention?
@CodeForYourself Жыл бұрын
You're totally right. 🤦♂️ This is what happens when I'm preparing videos at night 🤷♂️ I'll correct the slides and add an explanation here too. Thanks for your vigilance!
@CodeForYourself Жыл бұрын
Ok, I changed the underlying slides and added a correction as a popup to the video. Unfortunately I can't change the slides in the video but if it gets too annoying I will re-upload with a fix.
@andreibaraian88 Жыл бұрын
@@CodeForYourself awesome work nevertheless!!!
@WWraven2 жыл бұрын
Thanks for the video Igor. And is this a traditional Ukrainian shirt ? I love it. I always am fascinated by this folklore.
@CodeForYourself2 жыл бұрын
Yes it is a (fairly) traditional Vyshyvanka (вишиванка). Thanks for noticing!
@marwanzaghloul6065 Жыл бұрын
i think the solution will be using ssize_t as their will be remaining operation at the end of iteration that i will be -1 be fore check the condition so this will conflict with unsigned types
@CodeForYourself Жыл бұрын
I just realized I never answered here. I think you're thinking in the right direction. If you ask me the proper way to deal with this is to make sure we are operating with signed entities any time we use the minus sign. Although we should be careful as signed numbers can represent smaller numbers than the unsigned ones.
@chrislee12992 жыл бұрын
Solution to the exercise is, use int instead of auto because with auto it never reaches to negative value and hence you get infinite loop!
@ramcharanthota10162 жыл бұрын
My solution:- The data type of i when used auto is unsigned long.So, when we --i when i=0 it will got its largest value possible. One way of solving it, replacing auto with int
@ChrisOffner2 жыл бұрын
However, if we then have the *-Wsign-conversion* flag on, we'll receive an *error: implicit conversion changes signedness: 'int' to 'std::vector::size_type' (aka 'unsigned long')* How would we proceed here? Cast *i* to an *unsigned long* before using it to index into *numbers* ?
@ramcharanthota10162 жыл бұрын
At first glance, looks like it is due the value of 'i=numbers.size()=3' as mentioned in the lecture notes. But,it is a typo i guess.
@CodeForYourself2 жыл бұрын
Sorry, I did not fully get it. Which typo do you mean here?
@ramcharanthota10162 жыл бұрын
@@CodeForYourself In the 'using print statement' slide. the output from std::err prints i=3.if you access numbers[i=3] it will throw a segmentation error where the actual size of vector numbers is 3. I hope I am clear