Reputation: 1361
I have just learned C++ -- and I decided one project I am working for, I am better off going back to the drawing board and writing it from scratch in C++, rather than trudging on with C.
There is just one concern --- part of this project includes libraries. Some libraries will not be needed in C++, but some will.
I notice that the syntax for including library headers is different in C++ than it is in C. In C you write the following:
#include <someheader.h>
On the other hand, in C++ what you type is the following (if it is a C++ library):
#include <someheader>
Because of this, I am wary that there might be some differences in how I put together a C++ header file than in how I put together a C header file -- or at least some difference in how I name it in the file-system.
So does anyone have any information what I need to know in putting together a C++ library-header file as opposed to one for C?
Upvotes: 1
Views: 377
Reputation: 1976
Feel free to mix standard C headers with standard C++ headers. But be consistent. For C++ project use <cstdlib>
, for C use <stdlib.h>
, because C++ headers uses namespaces and you can avoid name collisions. All standard C headers duplicated in C++, so you can freely use C library in C++ code.
If you look to <cstdlib>
you will see that it includes <stdlib.h>
. It is true for other standard C headers.
Upvotes: 0
Reputation: 869
There is no difference. Most, if not all, of the standard C++ library include files do not have a .h
extension, to distinguish them from C library includes. The original C standard header file names are deprecated in C++, although virtually every compiler still supports them, and changed in name to c
followed by the original C file name, without the .h
extension.
For example: In C, the header file relating to strings is string.h
, but the C++ header file relating to strings is string
. The original C header file can also be accessed in C++ as cstring
.
Upvotes: 5