Namespaces
Variants
Views
Actions

Talk:cpp/language/modules

From cppreference.com

"Module units whose declaration has the keyword export are module interface units."

There are numerous grammar problems with this article. Although the article's content is much appreciated, it could be improved greatly by cleaning it up. For example, in my own struggle to understand module interface units and how unique they are, the above quoted sentence muddies the learning and understanding waters regarding plurality. The sentence should be this:

"Module units whose declarations have the keyword export are module interface units." or "A module unit whose declaration has the keyword export is a module interface unit."

If it had been written grammatically correctly, I would have immediately jumped to the correct understanding instead of wasting hours struggling with the semantic alternatives.

[edit] export keyword for export import is not optional, but rather signifies two different behaviors

export(optional) import module-name attr(optional) ;	(4)

In a primary interface module, whether or not the export keyword is present signifies two different functionalities at least in the MSVC compiler. For example, BEHAVIOR 1:

// primary interface module
 
export module module-name;
export import another-module-name;
 
export struct A 
{
  int MemberFunc();
}
 
// another primary interface module
export module another-module-name;
export implementation-body;
 
 
// usage
import module;
 
int main()
{
  A a;
  a.MemberFunc();
}

BEHAVIOR 2:

// primary interface module
export module module-name;
import another-module-name;
 
export struct A 
{
  int MemberFunc(); // in fact, 'import another-module-name' is not even necessary since this is a declaration
}
 
// another primary interface module
 
export module another-module-name;
export implementation-body;
 
// usage
import another-module-name;
import module-name;
 
int main()
{
  A a;
  a.MemberFunc();
}

My point is, the 'export(optional) ... (4)' text is misleading at best and not capturing any of this at worst. Rtischer8277 (talk) 14:47, 27 November 2021 (PST)