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

3

Reading this question , we are talking about adding headers to #include <filename> , the author speaks the following:

  

It is common to have these names that map to other files (eg, cstring -> string.h ).

Then these doubts came to me:

  • When using #include with quotation marks, is there a mapping when using #include "cfilename" to include filename.h ?
  • Compilers for have too many mappings in addition to cstdio - > stdio.h ?
asked by anonymous 28.09.2017 / 00:36

1 answer

1

When using include with quotation marks #include "filename.h" the preprocessor looks for the file first in the current directory and if it does not, it will look in the same places when using include with < > It is usually used to include files from the program itself.

When using #include <filename> the preprocessor will behave in a way that is dependent on which implementation it is using, but will usually look in the default includes first, so it is usually used to include headers from the default 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 C ++ (libstdc ++)

In spite of having the same functionality (this is mandatory), there are implementation differences mainly regarding the namespaces issue, where headers starting with C eg cstdio in C ++ place the definitions in the std namespace, while in stdio .h put in the global namespace, giving scope differences.

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

Most of the time it does not change much, now there are cases for example like in math.h vs. cmath where the implementation of the C ++ library changes a lot, especially the overloads for different types and const specifiers. link

So, at least in my opinion , it is wiser when programming in C ++ to always use

#include <cmath>

and when programming in C

#include "math.h"

    
30.09.2017 / 16:43