pugixml icon indicating copy to clipboard operation
pugixml copied to clipboard

Add inline variable support (external linkage for const vars)

Open ravstrix opened this issue 2 years ago • 4 comments
trafficstars

ravstrix avatar Sep 21 '23 09:09 ravstrix

Can you share the motivation for this change?

zeux avatar Oct 13 '23 17:10 zeux

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.

ravstrix avatar Oct 13 '23 21:10 ravstrix

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.

zeux avatar Oct 14 '23 03:10 zeux

It's code cleanup.

ravstrix avatar Oct 14 '23 11:10 ravstrix