Are string functions like strlen, strcpy, strcat really old and bad? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I asked a question about this topic and people say that there is something wrong with my university for teaching me these ancient library. Is it really true and what should I be using instead? Sorry I am still quite new I am in the first year.

Raw C strings are responsible for a significant percentage of security flaws in real world software.
Properly handling buffers is hard, and getting it wrong is depressingly common. There is a use for low level raw memory buffer manipulation of strings, but teaching it first is questionable.
One way of teaching C++ is to teach it as C, then add on some C++ features. Another is to teach it first as C++, and then add on the C compatible sub dialect.
The criticism you are hearing is objecting to the teach C then C++ option.
Learning how to program in C is great; trying to learn both C and C++ at the same time makes you a bad C and bad C++ programmer.
When C++ was first invented, this was a reasonable way to do it. There were C experts but no C++ experts. It has been a few decades since then, and best practices in C++ are no longer that similar to best practices in C, and vice versa.

Knowing what they do is useful since you may encounter ancient code that uses them.
But no, there is no need to use them in modern C++. By modern, I mean something that is being written now or has been written during this millennium.
One of the functions you mentioned, std::strlen is fairly OK to use. Technically you dont need it, but neither is it terribly bad to use.
what should I be using instead?
Most of the time: std::string and std::string_view and their member functions.

Related

which one between " c or c++ " should I learn for beginner for to use Arduino UNO? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I want to learn how to use Arduino, but it needs some code and there are 2 different options are c and c++. I am confusing that which one to learn "c or c++" at first (I mean for beginner)? are those both same? Actually, it's really really my first time to learn code for Arduino. also, can you tell me where can I learn from? Thank you :)
You mentioned two key words, Beginner and Arduino.
Decision on learning C++ first versus learning C first might
be a matter of opinion for the key word Beginner since many
who start with one can easily adopt for the other.
learning C++ first however has some advantages versus learning C first
for the key word Arduino which I explain.
Arduino programing is mainly targeted toward bare-metal programming, which includes dealing with many environmental options/variables which are usually known at the compiling time.
Programming methodologies which exists in C++ that address processing known factors at compiling time outnumber those of which exist in C by a large number!
Although I must add that these features rarely appear in user programming interface, if any! But still these features would be available for one to implement individually regardless of using Arduino or other bare-metal programming toolkits.
Further more multiplicity of the environmental options/variables demands a well established hierarchical ordering and management which is also more addressed in C++.
You can always try the Arduino website itself as an easy source either for learning or for tutorials/examples!
But to learn the language correctly and completely always keep an eye on authentic sources like cppreference.com and/or cplusplus.com.
Finally you can always ask/lookup your questions and seek guidance here!
Good luck!

What is the difference between C++ and Visual C++ and how to start with C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So I want to start learning how to make real games and programs, and I bumped into C++ but then I realized that there is also Visual C++. If there's any difference - tell me what it is. If you have any suggestions on how to start in general with C++ program making (not that black window), please let me know.
I just want a cool program to run code on (still don't know any IDEs for C++), and want to start coding real hardcore programs.
Thank you for all the answers in advance!
if you want to start coding and learning C++ I would recommend you to watch a bunch of tutorials, maybe even read a book about it. But the best way to learn coding is, to code. Write as many little programs as you can. Get used to the programming language, try out new things. Write useless programs noone needs.
It sounds like you are very new to all of this and in my opinion it could be to complicated to learn writing "real hardcore programs" in a short time. If you are not willing to put some effort into this you'll probably never write any "real hardcore programs". It is'nt as easy as you may think. You will have to learn a lot of things and it will probably take a while. But once you learned the basics it'll be fun to write your own programs etc..
In addition to #vveil answer:
Learn to think or write out what your program should do before writing any code. Even for smaller programs. You can check against you set goals if your coding was successful. Maybe come up with a sketch for more complicated programs (when it comes to inheritance). And you train to think before writing anything.
If you are really into it there are plenty of playful tutorials (learn-cpp) out there where the code quest is provided and you try to solve it. Sometime you can code online and do not have to bother about toolchain and environment.
Most important: Have fun!

How can I make C++ in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Well, i was learning, again, a little bit of c and was with a little curious about how did the C++ inventor made it. And some facts lead me to the information, that he created it using pure C(obviously), so i was thinking if there is any source or anything that could help me to do things in C, that i can do in C++, like templates, namespace, class, reference and others it doesn't matter how difficult it is, i want to at least have more notion, so if anyone know a reliable source and well written i would be glad.
Yes, many, many years back, the first C++ compiler, by Bjarne Stroustrup was a "frontend for a C compiler".
Today, it certainly isn't anywhere like that. Modern C++ compilers generate code directly from C++ constructs in intermediate form for the backend to process into machine code for the target. This allows the compiler to do a more direct job, and not rely on the C compiler "understanding" what is going on.
This page contains some reference material on the cfront:
http://www.softwarepreservation.org/projects/c_plus_plus/index.html#cfront
That page also has links for the 3.0.3 archived sources as unpacked and compressed form.
Note however that this release is 21.5 years old, and would thus, if it was a person be able to order alcohol in a US Bar after showing ID. This is NOT the modern standard C++ by any measure (and it may or may not generate code that is suitable for a modern C compiler, I have no idea)
With this quote to go with the 3.0 release from 1991:
Bjarne Stroustrup notes, "A warning that Cfront 3 is pre-standard and
emphatically not recommended for use or further development might be
in place."
Edit:
I did download the code in the (compressed) link above. It certainly doesn't compile on Linux without effort. More effort than I am willing to spend, really. One of the problems is that it's pre-ANSI C, so the compile complains about various functions not being declared (for example strcpy, strcat, etc), and there are OS choices, none of which is Linux.
I also don't think it is necessarily the best place to start learning compiler techniques.

Is using OOP in C++ ever a mandate for a professional C++ programmer? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
My title is rather self-explanatory. I've done research on that before asking this, and hope that I'll receive an informational response. I realize that, of course, it depends on the job, but as an enthusiast C++ programmer (along with a few other languages) I just don't like OOP. I don't like anything about it. So I'm wondering if I'll just have to get over it in order to move into a professional level of C++, or if I'll be okay without it.
You can write programs in C++ and do not use OOP, but professional programmer will have to deal with some one else's code all the time, including your coworkers, using third-party libraries etc. And most of the time OOP is used in C++. So yes, you need to know OOP very well and you will be forced to use it again and again if you stick to C++ in your career.
Most, but not all, of the difference between C and C++ is regarding OOP. Constructors, memory allocation, operator overloading, run-time library, templates -- all are designed with OOP in mind. Having using C++ and not mastering OOP would be difficult.
OOP is not that bad, you may think that OOP is all about:
class customer {
String name, phone;
void sellSomethingTo();
}
but in fact even basic parts of the language are OOP, strings, vectors, matrices, growing arrays, input/output etc.
As ptic12 mentioned, the C++ parts that make it different to C but are not OOP are namespaces, function overloading, stricter type checks, advanced variable scope and declaration.
If you're a brilliant C++ programmer but just hate OOP, you could still probably get hired depending on the job. However a professional C++ programmer should be knowledgeable in OOP and you should make an effort to learn it.

C++ for Objective-C programmer [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I know there are a lot of "Objective-C for the C++ programmer" information out there and it could be used the other way around. I'm just curious if there is anyone who has knowledge about a "native" "C++ for the Objective-C programmer" tutorial/book?
I'm actually looking to work in C++ in parts of a upcoming iOS project. Basically I need to do a lot of wrappers around C++ code.
(I do know that they can co-exist and that Obj-C is a subset of C, just like C++, however different reasons I would like to gain more knowledge into C++. Coming from a Obj-C background I just ask for some guidance on the matter.)
I don't know of a book for learning C++ for the Objective-C programmer. The fact that the Objective-C foundation libraries offer a lot out of the box (not to mention all the other frameworks which are part of the iOS and Mac SDKs, which is the main use-area for Objective-C) which is not covered by the C++ standard libraries might be a reason. The new C++11 standard and the boost C++ libraries go some way to bridging the gap.
There are quite a few articles which describe the main difference including this one.
The understanding of OOP you have aquired in Objective C as well as it's C subset (in your question you say "Obj-C is a subset of C", it's the opposite), will give you a big head start in learning C++, but it seems you have no alternative than to use C++ books and learn directly from them.
EDIT:
Adding the link to the SO post on good C++ books, suggested by #Bart in the comments.
Take a look at Pierre Chatelier's comparison of C++ and Objective-C.
This document is designed to act as a bridge between C++ and
Objective-C.
http://pierre.chachatelier.fr/programmation/fichiers/cpp-objc-en.pdf