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

Add inline variable support (external linkage for const vars) #581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ravstrix
Copy link

No description provided.

@zeux
Copy link
Owner

zeux commented Oct 13, 2023

Can you share the motivation for this change?

@ravstrix
Copy link
Author

Because global constants have internal linkage, each .cpp file gets an independent version of the global variable. Using inline variables solves this problem by using external linkage for such variables. This ensures that only one instance of the variable exists in all files in which it is included.

@zeux
Copy link
Owner

zeux commented Oct 14, 2023

Sure - however, these are numeric constants with a literal initializer; clang doesn't emit any symbols here, and gcc doesn't emit any symbols with -O1 or higher. This would be different if the address of the variables is taken, but that should be highly unusual. So I am curious if this is motivated by a specific problem, or is more of a general cleanup.

@ravstrix
Copy link
Author

It's code cleanup.

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

Successfully merging this pull request may close these issues.

None yet

2 participants