Il 24/10/19 20:49, Paavo Helde ha scritto:
> On 24.10.2019 21:15, Soviet_Mario wrote:
>> nothing particularly serious.
>> I was just considering that one could not always have the
>> full storage
>> (lifetime) control they expect.
>> I tend to think too much in a C-like mindshape surely
>
> What makes you think that? Are you maybe afraid that any
> dynamically allocated pieces in a static std::string object
> might somehow have shorter lifetime than the std::string
> object itself? That cannot be, this would ruin all invariants.
>
almost
I was thinking slightly differently.
The requirements of a pure static object (not using malloc,
which is suitable only for fixed size arrays and strings,
not to dynamic ones) would be assessed at startup, that is
at the earliest stage of runtine, when the program is loading.
Either the static ram is enough and the program goes on to
never mind about any more, or not and it aborts.
Dynamically allocation may happen at any time during the
run, and it can fail to provide ram umpredictably. So we
would have a strange STATIC object without storage. I'm not
saying this would be a common scenario : just a violation of
the pact of the reserved ram in advance.
Now when one use the STATIC qualifier it might want more
than one effect, but one of them is just : being sure since
load that the ram requirements of a crucial object are
fulfilled or else to abort.
A static string entailing some dynamic allocation is strange
to me
> Or more probably, maybe you think that the lifetime of a
> static std::string object has already begun before the
> program start, when it maybe occupies some bytes in some
> data section of the executable on the disk?
yes sort of
> No, it isn't, in
ah ... I take note :\
> C++ the lifetime of an object with a non-trivial constructor
> begins when its initialization is complete. This only
> happens at run-time.
necessarily so, but ... HOW EARLY ?
I believed STATIC qualified objects were to be created at
LOADING of the program, not later, at least RAM would have
been reserved : it the actual data for initialization became
available later, then that ram would have been inited later,
but still just reserved.
If not the staticness seems to me rather faint :\
but ok, nice to learn things and change mind about my
misconceptions.