Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ header unit importation syntax

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.

like image 970
user42768 Avatar asked Aug 23 '19 20:08

user42768


People also ask

Is #include the same as import?

#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.

How do I import a module into CPP?

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.

How do I include a .h file in CPP?

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.

How do I create a .HPP file?

hpp extension, just click New Item ~> Header File (. h) and at the bottom name it with . hpp extension. Alternatively you might create .


1 Answers

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.

like image 160
Michael Spencer Avatar answered Oct 23 '22 09:10

Michael Spencer