In the current C++ draft (august 2019), the grammar for a pp-import
http://eel.is/c++draft/cpp.import#nt:pp-import) allows for additional pp-tokens
after the header-name
or the header-name-tokens
.
The current version of that section is the result of P1703: "Recognizing Header Unit Imports Requires Full Preprocessing". Before the changes caused by this proposal, the grammar still allowed for preprocessing tokens tokens after the header-name
or the header-name-tokens
, but in the form of a pp-import-suffix
. (section [cpp.module] of P1103).
What is the reasoning behind allowing additional, unused preprocessing tokens in this context?
Thank you.
#import and #include are preprocessor directives for bringing in the contents of a header to a file. #include is replaced by the contents of the header directly, while #import is only replaced by the contents of the header the first time that header is imported.
You can use modules side by side with header files. A C++ source file can import modules and also #include header files. In some cases, you can import a header file as a module rather than include it textually by using #include in the preprocessor.
You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.
hpp extension, just click New Item ~> Header File (. h) and at the bottom name it with . hpp extension. Alternatively you might create .
They are there to allow for attributes.
The phase 7 (parsing and semantic analysis) grammar didn't change. Attributes are still allowed on imports. Previously the phase 4 (preprocessor) grammar tried to restrict more what was allowed as an import in order to enforce the rule that:
A pp-import is only recognized when the sequence of tokens produced by phase 4 of translation up to the import token forms an import-seq, and the import token is not within the header-name-tokens or pp- import-suffix of another pp-import.
The new rules restrict it even further by not allowing more then one import per line, so this rule and its associated grammar are no longer needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With