C++ Logo

std-discussion

Advanced search

Re: Global array of objects over multiple files

From: Federico Kircheis <federico_at_[hidden]>
Date: Thu, 17 Oct 2024 19:49:09 +0200
On 17/10/2024 19.35, Lénárd Szolnoki via Std-Discussion wrote:
> What happens when dynamic loading gets involved?
>
> My impression is that as presented it's only implementable for static linking, is that right?

It is implementable.
Without changing anything in the build system clang, gcc (thanks to
Thiago), and msvc do what I've described (msvc with the padding
unfortunately).

The "array" is created at compile-time, it does not execute any code
before main.
I would like to standardize the fact that there is an array and the
programmer does not need to use casts, and other low-level tools.


With shared libraries, every library has it's own array, just like other
global objects.

Since

  * shared libraries are out of the standard
  * I think it would make sense to standardizing existing practice, by
making it more available and programmer friendly

the standard is strictly speaking not concerned, but (I guess) it can be
mentioned in a note.

In all cases: it would be implementation defined.
Implementation (I guess) are encouraged to use their current
implementation (if they already have one).

> Note that on *nix shared objects are generally treated as any other TUs of the same program. Could this property be kept with the addition of a language feature like this, or such arrays would necessarily have hidden visibility implicitly?

I admit I did not gave too much thought about it, but this seems
orthogonal to what I'm proposing, as it concerns all global objects; is it?

Received on 2024-10-17 17:49:19