Common compilation flags and debugging a C++ program

  Рет қаралды 1,718

Code for yourself

Code for yourself

Күн бұрын

Пікірлер: 21
@CodeForYourself
@CodeForYourself 2 жыл бұрын
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-jw4bw
@Fabian-jw4bw 2 жыл бұрын
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_channel
@princepatel_channel 2 жыл бұрын
always - print statements
@ramcharanthota1016
@ramcharanthota1016 2 жыл бұрын
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.
@chrislee1299
@chrislee1299 2 жыл бұрын
I mostly use print statement because I feel it is more interactive to my code
@princepatel_channel
@princepatel_channel 2 жыл бұрын
thanks for introducing cerr. A new way of print statements.
@CodeForYourself
@CodeForYourself 2 жыл бұрын
Well technically we already talked about it in the streams video, but I'll take the "thanks" 😉
@andreibaraian88
@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
@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
@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
@andreibaraian88 Жыл бұрын
@@CodeForYourself awesome work nevertheless!!!
@WWraven
@WWraven 2 жыл бұрын
Thanks for the video Igor. And is this a traditional Ukrainian shirt ? I love it. I always am fascinated by this folklore.
@CodeForYourself
@CodeForYourself 2 жыл бұрын
Yes it is a (fairly) traditional Vyshyvanka (вишиванка). Thanks for noticing!
@marwanzaghloul6065
@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
@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.
@chrislee1299
@chrislee1299 2 жыл бұрын
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!
@ramcharanthota1016
@ramcharanthota1016 2 жыл бұрын
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
@ChrisOffner
@ChrisOffner 2 жыл бұрын
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* ?
@ramcharanthota1016
@ramcharanthota1016 2 жыл бұрын
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.
@CodeForYourself
@CodeForYourself 2 жыл бұрын
Sorry, I did not fully get it. Which typo do you mean here?
@ramcharanthota1016
@ramcharanthota1016 2 жыл бұрын
@@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
Functions in modern C++ and some related best practices 👌
23:47
Code for yourself
Рет қаралды 1,4 М.
CMake - the essential package
27:54
Code for yourself
Рет қаралды 11 М.
How Strong is Tin Foil? 💪
00:25
Brianna
Рет қаралды 69 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 33 МЛН
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 15 МЛН
"Hello, World" in 5 CURSED languages that no one should use
13:08
Dreams of Code
Рет қаралды 553 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 850 М.
Re-inventing move semantics in modern C++ in 13 minutes
13:20
Code for yourself
Рет қаралды 7 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 818 М.
How A Steam Bug Deleted Someone’s Entire PC
11:49
Kevin Fang
Рет қаралды 1 МЛН
Const correctness in C++
10:02
Code for yourself
Рет қаралды 3,3 М.
How Strong is Tin Foil? 💪
00:25
Brianna
Рет қаралды 69 МЛН