Latest Tech News

Stay updated with the latest in technology, AI, cybersecurity, and more

Filtered by: rbp Clear Filter

C++: Zero-cost static initialization

Zero-cost statics in C++ "Усердие все превозмогает!" К. Прутков, Мысли и афоризмы, I, 84 In C and C++ a static variable can be defined in a function scope: int foo() { static int counter = 1; printf("foo() has been called %i times. ", counter++); ... } Technically, this defines counter as an object of static storage duration that is allocated not within the function activation frame (which is typically on the stack, but can be on the heap for a coroutine), but as a global object. This is o

Topics: foo int mov rbp static

C++: zero-cost static initialization

Zero-cost statics in C++ "Усердие все превозмогает!" К. Прутков, Мысли и афоризмы, I, 84 In C and C++ a static variable can be defined in a function scope: int foo() { static int counter = 1; printf("foo() has been called %i times. ", counter++); ... } Technically, this defines counter as an object of static storage duration that is allocated not within the function activation frame (which is typically on the stack, but can be on the heap for a coroutine), but as a global object. This is o

Topics: foo int mov rbp static