I used c in a project, and after some study, I found a better method with some c++ libraries, but I really don't want to rewrite the code (say, printf
to cout
).
I did some search, and I got: "They are two very different languages", "DON'T DO IT", etc, but I never found a detailed explanation.
Why? Are there some recommended articles to read?
gcc is used to compile C program. g++ can compile any . c or . cpp files but they will be treated as C++ files only.
Compile and link multiple files: When -c flag is used, it invokes the compiler stage which translates source code to object code. When -o flag is used it links object code to create the executable file from file_name.o to a.
(debug) Inserting the `g' flag tells the compiler to insert more information about the source code into the executable than it normally would. This makes use of a debugger such as gdb much easier, since it will be able to refer to variable names that occur in the source code.
Compile is the creation of an executable program from code written in a compiled programming language. Compiling allows the computer to run and understand the program without the need of the programming software used to create it.
C++ is not a strict superset of C. That is, legal C code is not necessarily legal C++ code. Many of the typical differences are not syntactically valid in C++ and will fail to compile. For example:
void*
to T*
casts.A C++ compiler will generate errors about those, so those aren't too hard to find and fix if you have some patience.
Some differences could be valid in both languages but behave differently, however. Such cases are harder to detect. Some examples are shown at:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With