PDA

View Full Version : Using C libraries in C++



babyhuey
September 3rd, 2008, 11:10 PM
When programming in C++, can I use any C library in addition to C++ libraries or are there restrictions? I'm just curious, this isn't something I need to do atm. I just started using/learning C++. Most of my programming experience so far has been python and a bit of C#.

I just started my first computer science class(Structured Programming) at school which happens to use C++. So, no need for you python lovers to tell me not to learn C++ first =)

cabalas
September 3rd, 2008, 11:12 PM
To the best of my knowledge there isn't any limitations to using c libraries with c++.

cmay
September 3rd, 2008, 11:13 PM
yes . you can use the same libraries as in c with c++.
here is a link to a standard c/reference.
http://cppreference.com/

snova
September 4th, 2008, 12:54 AM
The only catch is that all declarations of C functions must be prefixed with


extern "C"
Or else the compiler will mangle the names for C++, and you'll get strange link errors...

Most C libraries do this already. They'll use a macro at the top and at the bottom that expand to this:


extern "C" {
and


}
Which simply causes the effect to be applied to all declarations within.

None of this applies to variables, fortunately.

Oh, and although I do like Python for certain things, I support your decision (unless it isn't!) to learn C++ first. Starting with a lower level language has its benefits in that you learn more about the computer itself, and how it works, while you're at it.

It additionally gives you an appreciation for higher level languages. :)