[ANSWERED] Include Files
-
Panke: The C/C++ standards do not specify the behavior of either #include <...> nor #include "...". Actually the included stuff is not even defined to be a file! The compiler is free to replace "#include <stdio>" with some piece of text that was compiled into it if it feels like doing so... There is no requirement of <> being a subset of "" in any standard. So much for the theory:-)
In practice <> is a subset of "" in most compilers. In general <> searches paths build into the compiler or set up by the build system (gcc: -I/some/path or -isystem /some/path, other compilers may or may not use similar switches) plus some default system pathes (e.g. /usr/include in Linux). "" usually does search in the current source directory first before checking the system paths.
-
According to K&R 2nd edition, appendix A.12.4 File Inclusion, "..." is a (not necessarily strict) superset of <..>:
bq. Similarly, a control line of the form # include "filename" searches first in association with the original source file (a deliberately implementation- dependent phrase), and if that search fails, then as in the first form[1]. The effect of using ', , or /* in the filename remains undefined, but > is permitted.
fn1. the first form is #include <filename>
[EDIT: fixed mistake, "..." is a superset, not a subset of <...>]
-
This code guru, so, my two pennies
GCC compiler and it's smaller brother MingW which comes with my Qt Creator has this to say about the preprocessor directive #include:
[quote]
#include <file>
This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).
#include "file"
This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option. [/quote]
Therefore, in my case, using Qt Creator with MingW, all none standard headers will be referenced with "..." . A compiler may not necessarily follow the paths as outlined in MSDN, unless I explicitly instruct my compiler to do so. (I am too lazy to do that) -
Good point, Taamalus.
C++ standards are sometimes (very) far from our real life.
The given environment determines the binding documentation, no matter how standards compliant it is.This problem is reflected in the acronym "RTFM":http://en.wikipedia.org/wiki/RTFM ;)
-
[quote author="Wolf P." date="1294651634"]Good point, Taamalus.
C++ standards are sometimes (very) far from our real life.
The given environment determines the binding documentation, no matter how standards compliant it is.This problem is reflected in the acronym "RTFM":http://en.wikipedia.org/wiki/RTFM ;)[/quote]
So, I guess the correct answer to RTFM then, is to ask RWFM?(the "W" standing for "Which")
-
For Qt, /I/ havn't read it nor searched for it ;)
But regarding my current main development environment, I have found that neither I nor my colleagues have read it early enough.When working with Qt Creator, you should consult one of the documentations of /MinGW/ or /Visua Studio/, depending on your software installation.
-
[quote author="Andre" date="1294653747"][quote author="Wolf P." date="1294651634"]This problem is reflected in the acronym "RTFM":http://en.wikipedia.org/wiki/RTFM ;)[/quote]
So, I guess the correct answer to RTFM then, is to ask RWFM?(the "W" standing for "Which")
[/quote]
That of the compiler(s) you use. As far as I know the popular ones tend to behave quite similar on include paths.
[EDIT: correct quotes]
-
"GCC Handbook":http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/index.html#Top
-
Wolf P.: You only use two compilers? You are lucky then!
Also note that the behavior of the compiler can change between versions (even though it should not change for fundamental things like include path handling:-).
-
"MSDN for MSVS":http://msdn.microsoft.com/en-us/library/36k2cdd4(VS.80).aspx
-
If you have more, please add them to the "Learning/Links and Material":http://developer.qt.nokia.com/wiki/Category:Learning::LinksAndMaterial page of the wiki