this post was submitted on 11 Apr 2024
7 points (100.0% liked)

C++

1865 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 2 years ago
MODERATORS
top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 10 months ago (1 children)

Aww, was hoping for some insight on global variable initialization order. It's something I've been curious about how different vendors order things with linking.

[–] [email protected] 4 points 10 months ago (1 children)

"Essentially at random, and it may change with build flags, compiler version updates, static v. dynamic linking, and who knows what else?" Can't rely on it, I'm afraid. What you can rely on is static init of local variables:

  static auto this_is_safe = QuilanType{};
  return this_is_safe;
}```
... Which will always give you a properly initialised 'global'.
[–] [email protected] 2 points 10 months ago

My C brain does not like static auto