Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it true that all c libraries can be used in c++?

Tags:

c++

c

Quite a newbie question as is.

like image 976
wamp Avatar asked Aug 26 '10 02:08

wamp


People also ask

Can you use libraries in C?

Functions in a C library can be used and accessed by programmers to create several different programs. As a programmer, you may find yourself using the same function or functions repeatedly. In this case, it is best to put this function or functions in a library to speed up the compilation of the program.

How many libraries are in C?

The ANSI C standard library consists of 24 C header files which can be included into a programmer's project with a single directive. Each header file contains one or more function declarations, data type definitions and macros.

Can C++ use all C libraries?

Oracle Developer Studio C and C++ compilers use compatible headers, and use the same C runtime library. They are fully compatible.

Can you use C without libraries?

If you disassemble the program, you can see only your code is there, there is no standard library bloat in it. So you can use C without the standard library.


2 Answers

Yes. There is no reason you cannot use C libraries in C++. Things change if you want to compile C in a C++ compiler. The C ABI is fully supported from C++, however things are not necessarily so neat from an API perspective. Certain C additions such as restrict are not in the C++ standard, and must be dealt with carefully.

like image 116
Matt Joiner Avatar answered Oct 13 '22 01:10

Matt Joiner


If the headers are properly protected with extern "C" { ... }, then yes.

like image 42
Stephen Canon Avatar answered Oct 13 '22 00:10

Stephen Canon