logo
down
shadow

Is it normal for C++ static initialization to appear twice in the same backtrace?


Is it normal for C++ static initialization to appear twice in the same backtrace?

By : user3865386
Date : January 10 2021, 01:57 PM
wish helps you Welcome to the "static initialization order fiasco". You should probably just read that entire article, as it will describe (in detail) how you may be running into this issue & how to fix it.
code :


Share : facebook icon twitter icon
Slime: frame-source-location not implemented / is my sldb Backtrace output normal?

Slime: frame-source-location not implemented / is my sldb Backtrace output normal?


By : user2606442
Date : March 29 2020, 07:55 AM
I hope this helps you . Since posting the question I have found this link which seems to indicate the Slime and clisp integration is not quite working as it should be.
So, in the meantime I have installed Steel Bank Common Lisp (sbcl), as easy as (on Ubuntu/Debian)
code :
sudo apt-get install sbcl
;;; Lisp (SLIME) interaction 
;;(setq inferior-lisp-program "clisp") 
(setq inferior-lisp-program "sbcl")
zero initialization and static initialization of local scope static variable

zero initialization and static initialization of local scope static variable


By : kraigrs
Date : March 29 2020, 07:55 AM
I wish did fix the issue.
I read several posts on C++ initialization from Google, some of which direct me here on StackOverflow. The concepts I picked from those posts are as follows:
code :
int const i = 5;     // constant initialization
int const j = foo(); // dynamic initialization
Java - Default Initialization of static variables before Static initialization

Java - Default Initialization of static variables before Static initialization


By : Vibin
Date : March 29 2020, 07:55 AM
will help you You are right.
Static fields and initializers are indeed executed in their declared order :
code :
static {
    System.out.println(Test.a);  // prints 0 -> default value for `int`
    a = 99; // a get 99
    System.out.println(Test.a); // prints 99 -> value after previous statement executed
}
why initialization of static member variable is not allowed inside class but initialization of const static members is a

why initialization of static member variable is not allowed inside class but initialization of const static members is a


By : Homan
Date : March 29 2020, 07:55 AM
Hope that helps One needs a bit of space in memory. Const do not - they can be hard coded.
Initialization of static member with same type as class (static initialization order problem)

Initialization of static member with same type as class (static initialization order problem)


By : user3248752
Date : March 29 2020, 07:55 AM
it should still fix some issue Based on your comments, I did the following:
made constructors constexpr made static members constexpr inline (you have to put them into the header file, not the .cpp), so C++17 is needed
code :
class Super
{
public:
    constexpr Super(const double a):
        m_a(a)
    {}

    double a() const { return m_a; }

    static const Super thing;

private:
    double m_a;
};

constexpr inline Super Super::thing = Super(1.0);

class Sub : public Super
{
public:
    constexpr Sub(const double a):
        Super(a)
    {}

    constexpr explicit Sub(const Super& obj):
        Super(obj)
    {}

    static const Sub thing;
};

constexpr inline Sub Sub::thing = Sub(Super::thing);

#include <iostream>

int main()
{
    Super super = Super::thing;
    std::cout << super.a() << std::endl;

    Sub sub = Sub::thing;
    std::cout << sub.a() << std::endl;
}
Related Posts Related Posts :
  • Sort an array via x86 Assembly (embedded in C++)?? Possible?
  • How to Replace only Part of the Variable using #define
  • How do you compare the performace of valarrays vs built-in arrays?
  • c++ generate a good random seed for psudo random number generators
  • Why isn't my operator overloading working properly?
  • Getting meaningful error messages from fstream's in C++
  • C++: Converting Julian dates to Gregorian
  • Could someone explain this interesting behaviour with Sleep(1)?
  • Is it possible to roll a significantly faster version of modf
  • Updating pointer using signals and slots
  • How are classes more secure than structures?
  • finding "distance" between two pixel's colors
  • C++ Greatest Number Verification
  • Why does my token return NULL and how can I fix it?(c++)
  • C++ enforce conditions on inherited classes
  • what happened if an exception is not captured?
  • Redundant naming in C/C++ typedefs/structs
  • question about STL thread-safe and STL debugging
  • killing a separate thread having a socket
  • Returning the size of available virtual memory at run-time in C++
  • Parallel computing for integrals
  • How do I force my std::map to deallocate memory used?
  • C++ Templates: implicit conversion, no matching function for call to ctor
  • Adding python script to c++ project
  • C++ private pointer "leaking"?
  • Initializing Primitive Array to One Value
  • how is push_back implemented in STL vector?
  • C++ Profiling: KiFastSystemCallRet
  • Multiple rows with a single INSERT in SQLServer 2008
  • Use super class's address/pointer in initialization list
  • double fork using vfork
  • Convert char pointer (char*) to struct
  • Does anyone have good tips for using pc-lint?
  • C++ How fast is passing around objects?
  • template type's ctor arguments at instantiation time
  • Get list of windows in taskbar on Windows 7?
  • Curl connection options
  • Best cross-platform solution for network server?
  • simple c++ file opening issue
  • Switching from C++ (with a lot of STL use) to C for interpreter building
  • How can I access the JPEG image pixels as a 3D array like we do in MATLAB?
  • What wording in the C++ standard allows static_cast<non-void-type*>(malloc(N)); to work?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk