Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SF.2 allow inline variables and static inline class member variables #2169

Open
sgilbertson opened this issue Jan 16, 2024 · 1 comment
Open

Comments

@sgilbertson
Copy link

SF.2 has a list under "A header file must contain only" that does not include:

  • static inline class member variables (not just functions)
  • inline variables not in a class declaration (again, not just functions)

Both are supported since C++17, resulting in all translation units linking the entity to the same memory location, The first point above results in code simplification and allows implementation of header-only classes that would otherwise not be possible. In [https://en.cppreference.com/w/cpp/language/inline](inline specifier - cppreference.com):

An inline function or variable(since C++17) ... has the same address in every translation unit.

For example, if a header includes:

class MyClass
{
    public:
        static inline int staticInlineMember = 5;
};
inline int inlineVariable = 5;

The memory location of staticInlineMember is always the same, when that header is included in multiple source files. So is the location of inlineVariable.

@iglesias
Copy link
Contributor

The last item of the list is ???, which I assume is a placeholder denoting that the list is not set in stone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants