You are here:

C/C++ an appetite

Advertisement


Question
Hi,
Just 2 questions:
-- Can everything that can possibly be done in C(like the low level stuff and the likes) be done in C++, and vice versa?
-- Can I use any C code in my C++ program, and vice versa?

Answer
Hello Heni

Everything you can do in C can be done in C++ because C++ is the entire C language plus extra features. Because of that, you can use C code in your C++ program. A C++ compiler will compile all C code (with some minor exceptions), but a C compiler will not compile C++ code. In other words, once you start using the C++ features, you need to move to a C++ compiler.

Now, I must explain the exceptions. The C++ language has more keywords than C. It has keywords like class, new, delete, template, and others. If you have C code that uses any C++ keywords as variable names, and you wish to compiler that C code with a C++ compiler, you will need to change those variable names to something else.

You can also link in libraries created with C compilers into both your C and C++ programs without recompiling the libraries. To do so, it is necessary to tell the C++ compiler that certain functions have been compiled by a C compiler. That is done with the extern "C" construct. For more information, see
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3

Best regards
Zlatko

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.