This talk is consistent with what others have been saying. Modern C++ written from scratch will most of the time use the newest and safest facilities provided by the latest STL versions, and we should reach to those by default. Especially the stuff about Bounds Safety and Memory Safety by default. But, the whole history of the evolution of C++ is still there, nobody is taking it away with very few notable exceptions. Old code uses it, directly and new code that is doing the hard work of providing the safer and more robust interfaces uses it under the hood. Good stuff!
Great talk to demistify c/c++. But i think that having distinct operater for ptr , deref ,and ref rref will automatically demistify c/c++. because of operater overloading optical illusion occers. Which causes confusion. Which lead to brain stall to dectect errors which can be easily dectected while coding. If we avoid same operater for different functionality.
The talk is fantastic, not sure I am buying the details of the example used to show the hazards of comparisons between size_t and ptrdiff_t, which is a real hazard. We never initialize field on screen, but if there are no commas occurring between its start and the null terminator, we get back nullptr, and length becomes a huge positive number. The example shown could presumably be fixed by adding: if (nullptr == field_end) field_end = strchr( field, '\0'); before calculating the length, but signed unsigned comparison is always a hazard to watch out for nevertheless.
++rating for mentioning that tho the optimizer will probably make sure there is no difference on built-in types when the result is thrown away, the meaning of ++var and var++ is distinctly different, and most of the time when people write var++ they actually mean ++var. This is indeed a bad habit to get into for the times it will make a difference in behavior.
Very good stuff, thank you. I have a question about const pointer. After deallocating the memory where a const pointer is pointing to, the const pointer becomes a dangling pointer and I cannot make this pointer point somewhere else. How can we deal with this situation?
Hi, that would be a huge "code smell", in the sense of bad designed code. In that situation you would want to reformat your code to ensure that the const pointer never outlives the pointed object.
How would you want to deal with this situation? What is wrong about it and why this situation requires dealing with? You made a pointer const so... it is const :-)
+1 for correctly defining dangling pointers. Too many people use the term in reference to memory leaks. The most bizarre and hard-to-debug misbehavior imaginable comes from reading, and worse still, writing to them....they are an OSHA and ISO-certified workplace safety hazard!
I don't think dereferencing nullptr will ever _not_ segfault. I could be wrong, but unless you're using some ancient system from the 80s, it'll always segfault.
One of the BEST Talk about *Pointer &Reference I've ever seen! Thank you so much, Sir. Ben Saks!
Even with all the scorn raw pointers are getting, I still love them.
I think they are cool. It's the granular control that makes it useful for certain applications.
This cleared my all doubts related to pointers... Great talk Ben. Cheers!
This talk is consistent with what others have been saying. Modern C++ written from scratch will most of the time use the newest and safest facilities provided by the latest STL versions, and we should reach to those by default. Especially the stuff about Bounds Safety and Memory Safety by default. But, the whole history of the evolution of C++ is still there, nobody is taking it away with very few notable exceptions. Old code uses it, directly and new code that is doing the hard work of providing the safer and more robust interfaces uses it under the hood. Good stuff!
Thank you for you comment. It is very helpful.
Thank you Ben Saks for another very informative and very needed talk. I really need to go back to basics.
Glad it was helpful!
Simply the best talk about pointers and references
Excellent resource! Thank you for delivering this talk
I watched just as repertory... but then I learned something new.
This is the best explanation. Thank you for this!
Great talk to demistify c/c++. But i think that having distinct operater for ptr , deref ,and ref rref will automatically demistify c/c++. because of operater overloading optical illusion occers. Which causes confusion. Which lead to brain stall to dectect errors which can be easily dectected while coding. If we avoid same operater for different functionality.
Simple topic, but well presented / explained.
The talk is fantastic, not sure I am buying the details of the example used to show the hazards of comparisons between size_t and ptrdiff_t, which is a real hazard. We never initialize field on screen, but if there are no commas occurring between its start and the null terminator, we get back nullptr, and length becomes a huge positive number. The example shown could presumably be fixed by adding:
if (nullptr == field_end) field_end = strchr( field, '\0');
before calculating the length, but signed unsigned comparison is always a hazard to watch out for nevertheless.
Amazing lecture, keep up
Really interesting.. Thanks
++rating for mentioning that tho the optimizer will probably make sure there is no difference on built-in types when the result is thrown away, the meaning of ++var and var++ is distinctly different, and most of the time when people write var++ they actually mean ++var. This is indeed a bad habit to get into for the times it will make a difference in behavior.
Very good stuff, thank you. I have a question about const pointer. After deallocating the memory where a const pointer is pointing to, the const pointer becomes a dangling pointer and I cannot make this pointer point somewhere else. How can we deal with this situation?
Hi, that would be a huge "code smell", in the sense of bad designed code. In that situation you would want to reformat your code to ensure that the const pointer never outlives the pointed object.
How would you want to deal with this situation? What is wrong about it and why this situation requires dealing with? You made a pointer const so... it is const :-)
+1 for correctly defining dangling pointers. Too many people use the term in reference to memory leaks. The most bizarre and hard-to-debug misbehavior imaginable comes from reading, and worse still, writing to them....they are an OSHA and ISO-certified workplace safety hazard!
I don't think dereferencing nullptr will ever _not_ segfault. I could be wrong, but unless you're using some ancient system from the 80s, it'll always segfault.
Great presentation, Ben! Thanks for making this.