Is there inclusion mapping for ' #include "cmylib" '?

Asked

Viewed 77 times

3

Reading that question, there is talk of the inclusion of headers in . In the answer accepted, section #include <filename>, the author speaks the following:

it is common to have these names mapping to other files (eg.: cstring -> string.h).

Then I had these doubts:

  • When using #include with quotes, there is mapping when using #include "cfilename" to include the filename.h?
  • The compilers of has other maps besides the cstdio -> stdio.h?

1 answer

1


When using include with quotes #include "filename.h" the Preprocessor looks for the file first in the current directory and if it does not find it, it will look in the same places when using include with < > Usually used to include files from the program itself.

When using #include <filename> the Preprocessor will behave in a manner dependent on which implementation it is using, but will usually look in the normal (default) location of includes first, so it is usually used to include headers from the standard library.

That said, it is important to note for example that string. h and cstring are not the same thing string. h is a C header (libc) and cstring is a C++ header (libstdc++)

Although it has the same functionality (this is mandatory), there are implementation differences mainly on the issue of namespaces, in which headers that start with C ex.: cstdio in C++ put the definitions in the Std namespace, while in stdio. h put in the global namespace, giving scope differences.

If you read the headers, you will see that in cstdio of libstdc++ you will find a #include "stdio. h" of the libc, and some implementation details because in fact what this header does is a wrapper to use this C library according to the C standard++.

Most of the time it doesn’t change much, now there are cases for example as in Math. h vs cmath in which C++ library implementation changes a lot, especially overloads for different types and const specifiers. https://stackoverflow.com/questions/8734230/math-interface-vs-cmath-in-c/8734292#8734292

So that,at least in my opinion, is more sensible when programming in C++ always use

#include <cmath>

and when programming in C

#include "math.h"

  • The difference between <cmath> and <math.h> is the namespace. All functions of <math.h> are declared in the global scope while in <cmath> they are within the standard namespace: std.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.