Advantages and Disadvantages of C++

Hello Masters,

Greetings!

I'm reading some articles regarding c++ Vs C# and i saw this disadvantages of C++.
Can someone of masters explain the below disadvantages?

Disadvantages:
1.) It has no security
2.) Complex in a very large high-level program.
3.) Used for platform specific application commonly.
4.) For a particular operating system or platform, the library set has usually chosen that locks.
5.) When C++ used for web applications complex and difficult to debug.
6.) C++ can’t support garbage collection.
7.) C++ is not secure because it has a pointer, friend function, and global variable.
8.) No support for threads built in.


Additional:

Compiler warnings: C++ will let you do almost anything provided the syntax is right. It’s a flexible language, but you can cause some real damage to the operating system. C# is much more protected and gives you compiler errors and warnings without allowing you to make some serious errors that C++ will allow.
Last edited on
No support for threads built in.


Threads became part of the C++ standard library in 2011. You're working from a very out-of-date source.
1) this is an advantage. You add security where you need it, libraries do this for you, and there are tools and even compiler warnings to find security problems, but you can skip the overhead of something you do not need in many programs. Not everything is connected and needing security, though much of it is these days, many embedded things still don't need and can't afford the overhead.

2) all code is complex in large programs. This is a bland uninteresting statement.

3) also an advantage. Portable code is slower code, generally. C++ is portable until you start talking gui or OS level stuff. The languages that abstract gui and OS calls to a common format add a layer of overhead to do so that translates from an intermediate step to the local calls.

4) this did not survive google translate. it is nonsense.

5) c++ is not meant for web development, this is true. It can do it, but there are better tools. This is like saying HTML isnt good at linear algebra. The difference is, c++ can do it.

6) GC is supported, simply add it to your code. It isnt built in, see #1, its overhead that we don't want or need in embedded / performance code.

7) c++ is powerful because it has pointers and friends. No one sane uses globals, even if allowed.

8) see above.

Advantage/disadvantage is from point of view. I guess if you need your hand held and want slow code, c++ isnt for you.

c# isnt well supported off windows. Its not really saying much about portability there. Being on windows, talk of security is sort of amusing as well.
Last edited on
closed account (E0p9LyTq)
I'm reading some articles regarding c++ Vs C# and i saw this disadvantages of C++.

Anyone that writes that C# is superior to C++ is lying. Portability alone doesn't happen with C#, it is firmly tied to Microsoft Windows. Every modern OS other than Windows has C++ compilers available.

The rest of the talking points are equally laughable. Thinking they are unbiased is just plain wrong.
No one sane uses globals, even if allowed.

I sometimes use std::cout and std::cin. I guess I must be insane.
functions are not variables. and std isnt the global scope, its the std scope. Are you really trying to associate subroutines with the global variable problem? And why? Cout is nothing like

int x; // this is like cout???
int main()
...

std::cout and std::cin are variables.

To me a global variable is a variable that can be accessed anywhere in the program.
Last edited on
I have a stricter definition of variable.
If it is defined
type name;
and you can do this
name = value; // this excludes constants and routines.
its a variable.
if not, it isnt a variable, to me.

But I can see how with your definition you would take my above statement as a problem.
Or, in short, my def of variable is pretty much the math one.
Disadvantages:
1.) It has no security
Define "security" please, and show me a language that has it. Are you talking about a built-in catch-all or something, because even high-level languages will crash if you do something stupid.
2.) Complex in a very large high-level program.
If an app didn't get more complex as it got larger, I'd be surprised.
3.) Used for platform specific application commonly.
It's the fastest, if not of the fastest, platform-specific languages. This is why it's used. Most operating systems are based on C, after all.
4.) For a particular operating system or platform, the library set has usually chosen that locks.
jonnin's answer
5.) When C++ used for web applications complex and difficult to debug.
jonnin's answer
6.) C++ can’t support garbage collection.
Stick with STL containers and general RAII principles and you'll be fine. Vectors, streams, etc. clean themselves nicely when they're done
7.) C++ is not secure because it has a pointer, friend function, and global variable.
friend is a little weird and low-level pointers can get nasty, but there are usually ways to redesign to not do this. friend is rare and usually for convenience of private var access, but absolutely not necessary. You can write public getter methods if you want someone to access some of your private vars, for example.
8.) No support for threads built in.
Repeater's answer

The topic is completely biased and lists only imaginary "disadvantages" -- to be true to the title, what are the advantages from your supposed article?

In any case, the OS is usually smart enough to protect against a program trying to change a memory addresses already in use. It's not like writing to an index out of bounds will suddenly cause your Desktop to start melting, lmao.
@icy1,
one meaning for security is that the permissions of can be restricted.
.NET and Java apps run in a kind of sandbox so the runtime can prevent some malicious or dangerous activities.
For example in .NET apps you can't write to the registry without being admin and some more things.

BTW C++ and C# are totally different beasts so we are comparing apples and pears. They are both fruits and grow on a tree. C# and C++ have only some syntactic similarities.
Last edited on
closed account (E0p9LyTq)
BTW C++ and C# are totally different beasts so we are comparing apples and pears. They are both fruits and grow on a tree. C# and C++ have only some syntactic similarities.

The use of namespaces in C# vs. C++ comes to mind why comparing the two is a fool's errand.
https://stackoverflow.com/questions/17822096/why-using-namespace-directive-is-accepted-coding-practice-in-c
For example in .NET apps you can't write to the registry without being admina

I'm fairly sure you would get Access Denied (error 5) when doing the equivalent operation in Win32 C++ as well. I'm curious to see an example of this, you could be completely right.

______________________________________

The main criticism in the OP's post can be summarized as "C++ lets you do more things to shoot yourself in the foot". I agree, it does.

But OP's list is strange to me. Half of them aren't really advantages or disadvantages, they're just different designs or goals of the different languages. C++ can be just as platform independent as C#, and C# .NET has platform-specific things as well. C++ can wring out every last bit of performance if necessary. "Friend" functions have nothing to do with security, so I don't understand this point. Not having pointers does make safe-part of C# less complex, sure, but I still don't really consider that a disadvantage.

I agree that not having built-in security can be a disadvantage for some applications. It depends on what you're doing. The concept of "undefined behavior" in C++ can be one of its downsides. If you don't know what you're doing when it comes to security, then don't expect C++ to correct your ignorance.

Here are some thoughts on C# I had, copied from another thread:

C++ is of course much more powerful, but I find C# much quicker to make a variety of programs in than C++, and much easier to spot bugs in. For example, you want a stack trace? In C# it's just Environment.StackTrace. In C++, there is no standard solution, you either need to use a specific compiler, and write your own wrappers, or use an external library like boost or StackWalker.

C++ has so much "gotcha" behavior when you get into the nitty-gritty details. For example, the fact that short-circuiting does not happen when you use an overloaded && or || operation. There's other examples, but in general it's just not intuitive behavior at times. The concept of "undefined behavior" means that your program will never be completely secure unless you provide wrappers around places that may expose undefined behavior, such as preventing integer overflow with checks before you actually perform the addition or multiplication. C#, on the other hand, has a simple "checked" keyword that will throw an exception on overflow, instead of causing your whole program to become illegal.

C# intellisense/compiler errors tend to be very clean. C++ compiler errors are the opposite. Considering that templates in C++ are turing complete, and that the syntax of C++ is just more complicated in general, IntelliSense tends to be horrible at diagnosing all the possible problems, and template compiler errors just look horrendous in C++.

And as Thomas1965 noted, C# does have operator overloading, but the degree of freedom that C++ allows in operator overloading can be more of a curse than a blessing, at times. Sure, for many aspects of C++, once you learn about them you can consciously avoid doing them, but, in a nutshell, what I'm saying is that there are so many more ways to do something wrong without knowing it in C++ than in C#.

In C#, I dislike the "using" feature when working with disposable objects. As a user of a class, I shouldn't have to know whether or not something is Disposable and I need to handle it differently, else have some sort of resource leak. This is where C++ destructors are actually really useful, although problems with C++ destructors include knowing that you shouldn't ever throw an exception inside of a destructor, another gotcha.

I also like how C# limits the use of macros.

I admit I have not done multi-platform programming C#, but I thought C# has been pretty stable with support for other platforms for a while now.
Last edited on
Yeah, I should have emphasized me saying "the safe part" of C#, since pointers require you to explicitly say you know you're writing "unsafe" code. But you're correct.
closed account (E0p9LyTq)
since pointers require you to explicitly say you know you're writing "unsafe" code.

Ever look at the smart pointers C++ has to offer? They are not "unsafe."
Ganado wrote:
"the safe part" of C#

Perhaps I should have said,
since pointers in C# require you to explicitly say you know you're writing "unsafe" code.
to remove ambiguity.
Last edited on
Topic archived. No new replies allowed.