Can C/C++ really do everything?

I''ve been learning some C/C++ in my university but I feel like we're missing something. Every programmer says that C++ can do everything. However, all i see is a black console waiting to read and to print things. No buttons, graphics or anything. Also, we have supposedly learned all commands, but i feel like i can't do much just with them! Nothing like the so nice programs you may see around. Am I missing something??
You are working in console programming there is also GUI programming with c++, they normally won't teach that when you just start learning a language. If you are still interested you could check out SFML/SDL or Qt. There is also the windows/*nix API's as well.
Please correct me if I am wrong but everything is basically written in C/C++ (and maybe a little bit assembler).
I don't know what programming languages you are comfortable with but just so you know here are some other programming languages you might know.
All of those are written in C/C++:
- C#
- Java
- Python

So everything you can do in C#, Java and Python can also be made in C++.
If you want to make a GUI with buttons etc there are free APIs available.

If you care about cross-platform development take a look at Qt (just google it).
Even if you don't care about that Qt is still the best choise you could make in my opinion.
Qt is pretty awesome and the GUI Designer is in my opinion far surperior to that of either C# and Java.
Last edited on
"Please correct me if I am wrong but everything is basically written in C/C++ (and maybe a little bit assembler)."

You're wrong. Just because a program written in python is runned by an environment written in C, that doesn't mean the program is written in C.

It's a very odd question when someone asks "can X do everything". Well, no. For instance, you have to use assembly to switch the processor to protected mode. Also some functionalities needed to write boot loaders.

A programming language can do as much as the libraries and APIs/ABIs it can use allow it to. In case of C and C++ that's a lot, at least at the moment. Why? Because APIs are written for C and C++, and not just because C and C++ are overlord languages that conssume every other language in the universe. C/++ compilers are assembly generators, which means they can be fast, which means they can be used to solve a lot of problems.

Of course this doesn't really go into the issues of weather or not a "tool is right for the job", but I hate that discussion anyway.

These are my oppinions:

C++ can be used effectively for many many tasks (if not all), other than scripting programs. It is extenssible (as in, it can express a wide range of ideas), and it allows us to write pretty uniform interfaces. It can be faster than C (at least without some serious and seriously messy preprocessor heavy lifting or seriously convoluted code), but it often is not, since the facilities provided by C++ introduce a lot more cases to a compiler, which make it harder to optimize.

There is no reason to pick java over C++ if you have a choice, and there is no reason to implement a c++ compiler for a system rather than a java environment. I believe it pays off massively to implement a C++ one. Java has a faulty model and no programming language should be built around only one programming concept. Not to mention the appaling ideas and implementations found all throughout that abhorrent language. I picked on java here because it does seem the language that gets presented as an alternative to C++ because of features like garbage collection and such. Hell, C++ has a better garbage collection system than Java, but whatever.

And sorry to burst your bubble, but you wont learn C and definetly not C++ from school. You better start reading and getting your hands dirty.
Last edited on
And now for the Albatross to swoop in and be nitpicky.

C++ can be used effectively for many many tasks (if not all), other than scripting programs.

Programs can be written to be extensible using shared objects written in C/C++ (see HexChat). You'd just need to call the platform-specific APIs for doing so, as currently this functionality isn't implemented in the standard library.

It can be faster than C (at least without some serious and seriously messy preprocessor heavy lifting or seriously convoluted code)

You elaborate on this later, but as for seriously convoluted code or preprocessor heavy lifting... have you seen some of the stuff people do with template metaprogramming?

There is no reason to pick java over C++ if you have a choice
In cases where platform independence is very important, a solution wherein a JIT compiler and/or virtual machine are used is perhaps the best. Currently, as far as I know, there is no single widely-accepted virtual machine for C++ (though LLVM may change this), where Java is by definition built off of one.

there is no reason to implement a c++ compiler for a system rather than a java environment

And how do you suppose the Java environment is implemented? Furthermore, it's actually really hard to implement C++ for a Java environment. There would need to be a lot of native code added to deliberately circumvent some of the Java environment's safety features (including memory access), and almost invariably it would have to violate some part of the C++ standard where a certain implementation cannot be followed.

Java has a faulty model and no programming language should be built around only one programming concept.

Tell that to the lispers or the folks who write assembly. :D

Hell, C++ has a better garbage collection system than Java, but whatever.

Technically, C++ doesn't mandate garbage collection. C++11's spec was written such that a garbage collection system could be introduced, but in practice none of the major compilers offer one (AFAIK, I know for sure clang doesn't). C++ follows the principle of RAII, which isn't exactly garbage collection, and is in some cases incompatible with garbage collection.

And sorry to burst your bubble, but you wont learn C and definetly not C++ from school. You better start reading and getting your hands dirty.

Some schools do offer C/C++ courses, though indeed these are generally terrible and learning yourself (as long as you have the discipline) is the better option.

-Albatross
Last edited on
Programs can be written to be extensible using shared objects written in C/C++ (see HexChat). You'd just need to call the platform-specific APIs for doing so, as currently this functionality isn't implemented in the standard library.


I honestly don't know much about this, when I said what I said I was wanting to speak more through the speed side. I see no reason why other languages shouldn't be capable of directly tapping into the ABIs given the right functionality.

You elaborate on this later, but as for seriously convoluted code or preprocessor heavy lifting... have you seen some of the stuff people do with template metaprogramming?


Again, C++ is not the cleanest language, and I avoided it for ages because of that. However, templates are much more flexible than the preprocessor. Jesus, last time I tried to implement a simple type substitution mechanism to write type generic structures and functions I had to use 3 definitions to do one thing. And this is not me being an idiot, you literally need one definition to expand arguments and another one to concatenate the arguments. Or at least this is so with GNU's pp, not sure what the standard says. Not to mention I couldn't implement header guards as usual due to no macro expansion in conditionals.

In cases where platform independence is very important, a solution wherein a JIT compiler and/or virtual machine are used is perhaps the best. Currently, as far as I know, there is no single widely-accepted virtual machine for C++ (though LLVM may change this), where Java is by definition built off of one.


If you want to target platforms which present a java environment and not a C++ compiler, you have little choice other than to use java. Also, languages don't need to be interpreted to be portable. A C compiler is way easier to implement than a Java environment.

And how do you suppose the Java environment is implemented? Furthermore, it's actually really hard to implement C++ for a Java environment. There would need to be a lot of native code added to deliberately circumvent some of the Java environment's safety features (including memory access), and almost invariably it would have to violate some part of the C++ standard where a certain implementation cannot be followed.


Cross compilers I would think. You don't need a C compiler working on a system to write programs in C for it. You just need to have a C compiler and linker that targets it. I see no reason to implement a java compiler and interpreter if you have a C++ one. Ok, maybe the fact that so many people develop in java (which is a damn shame if you ask me), helps.

Tell that to the lispers or the folks who write assembly. :D


Lisp is a generic language. I use it often and I quite like it. Ironic that lisp as a stronger model of object relations than Java huh?
Assembly is besides the point. It should not be seen as a "programming language" but as a direct alias for processor instructions. Besides, I don't think assembly documents enforce any programming models on you what-so-ever. Whatever limitations you may feel from writting assembly come from the simplicity of the language and not from a desire to enforce some arbitrary set of rules.

Technically, C++ doesn't mandate garbage collection. C++11's spec was written such that a garbage collection system could be introduced, but in practice none of the major compilers offer one (AFAIK, I know for sure clang doesn't). C++ follows the principle of RAII, which isn't exactly garbage collection, and is in some cases incompatible with garbage collection.


unique_ptr and shared_ptr have been a thing since C++11. And even in a primitive 98 compiler they are very very easy things to write. Those together with destructors present a much more elegant solution than java.
Last edited on
Also, languages don't need to be interpreted to be portable. A C compiler is way easier to implement than a Java environment.

True and probably true, respectively, but how about all the libraries that you'll likely be linking against?

Cross compilers I would think. You don't need a C compiler working on a system to write programs in C for it. You just need to have a C compiler and linker that targets it.

One way or another, a compiler must still be written to target that platform, and then it can become very difficult to test or benchmark your code. Although, it appears that I had misunderstood you. I thought you were talking about implementing a C++ to Java Bytecode compiler. Whoops!

I see no reason to implement a java compiler and interpreter if you have a C++ one.

Specifically because of portability reasons. It can be very awkward to compile and test a program for another platform with its own specific APIs, especially in the case of targeting Mac OS. When implementing a Java platform, you can fairly reliably develop for and test for any platform that supports Java (with a few standard library exceptions and a case where you need to use JNI), and gain access to a wide variety of programs written in Java. That alone could be reason for some.

Besides, I don't think assembly documents enforce any programming models on you what-so-ever.

They absolutely can and in some cases should. Most processors support extensions to their base instruction set, and sometimes those extensions should be preferred or deprecated depending on the requirements of the project.

unique_ptr and shared_ptr have been a thing since C++11. And even in a primitive 98 compiler they are very very easy things to write. Those together with destructors present a much more elegant solution than java.

And before that there was the ever easy to abuse auto_ptr. My point is different. RAII and garbage collection aren't synonymous concepts, though I agree that RAII is more elegant.

-----

Full disclosure, I spent roughly two years in Javaland and came out hating it. I'm an "evil" C++ programmer. Programming in Java made me feel like I was programming naked in a padded room that doubles as a children's daycare center. However, I don't think it's necessarily bad to learn. I definitely learned a healthy amount about object oriented programming strategies, and about how spending years programming exclusively in very high level languages can rot your brain.

-Albatross
Last edited on
but how about all the libraries that you'll likely be linking against?


Well, the C standard library is one of the smallest standard libs around. And the libraries themselves are often written in the language they're meant to be used with, so that shouldn't be much of a problem unless you specifically have to write you own libraries, which would be quite insane if we're talking about C++, so that could be a problem.

RAII and garbage collection aren't synonymous concepts, though I agree that RAII is more elegant.

Yeah, I know I implied they were the same thing, but I was refering to garbage collection as general automatic resource management. I got carried away.

It can be very awkward to compile and test a program for another platform with its own specific APIs, especially in the case of targeting Mac OS.

The standard C++ library has a lot of standardization now-a-days regarding many previously highly environment specific tasks such as multithreading and reading times. You're still right on that. Cross compilers might be hard to come by, and there might be subtle changes or bugs specific to compilers targeting a certain environment, but still, I would prefer a world without java in it. If you don't need the greatest and latest in speed you can use any other of the many great interpreted languages available (Common LISP is a great alternative for instance, but how many people really know LISP right?) The problem with java is not as much that it is a terribad language, is that people overuse it to death even on cases where they have no reason to not use C++. Then that propagates. And each time you want to get something done you find the number of non-java tools lacking. And each time you get contracts you need to work with java. And each time you work with someone else, they only know java.

Java is the PHP of the non-web dev world (although nearly as bad as PHP.)

I blame schools. Kids these days and their javas.
Topic archived. No new replies allowed.