+ 1
How to write c++ programs correctly
new beginner
3 odpowiedzi
+ 6
If you're a beginner, let me just say that C++ has a number of things to look out for that you don't have to worry about in an alternate high performance systems languages like Rust. C++ gives you exactly what you asked for and this can lead to hard to find bugs when all you see in the output is "Segmentation fault (core dumped)", while Rust would stop you from implementing the bug at all. C++ requires you to know how to write the program correctly and doesn't enforce or encourage best practice. C++ gives you complete freedom.
If you're set on C++ like I was, practice, learn everything, and don't give up when it gets hard. If you don't want seg faults, dangling pointers, data races, or a bad tool chain, use Rust (it's great and I came to it after C++)
+ 5
C++ is the best language available for lots of things, but as Maxwell pointed out the freedom can get you. You can't count on anything. I've got code to demonstrate modifying declared constants. You can modify call frames so functions don't return to their caller. Depending on the os memory protection, you can modify the code you're executing. In fact, before thread libraries existed, it was an accepted method to switch threads by modifying the code. Needless to say, debugging that stuff can be difficult. Imagine your constant PI definition randomly changing in the middle of usage screwing up your screen display. How you going to track that problem down!?
You best bet to program C++ correctly is to watch for screwups in pointers or arrays. Most problems are using pointers as type a, when it points to a type b. You can also have a pointer to a pointer to type a and forget a level of indirection. It is simple to let the index of an array reference outside the array so definitely keep close watch on those.
+ 1
thanks Maxwell