Created
May 6, 2022 10:42
-
-
Save reyoung/de009c0532caf2a7551663e6a6c37fe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "a.h" | |
#include <iostream> | |
static int _inited = []() -> int { | |
std::cout << "NS: " << NSFoo() << ", Static: " << StaticFoo() | |
<< ", Inline: " << InlineFoo() << ", Cls: " << Foo::ClsFoo() | |
<< ", Weak: " << WeakSymbFoo() << std::endl; | |
return 0; | |
}();⏎ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
namespace { | |
int *NSFoo() { | |
static int val; | |
return &val; | |
} | |
} // namespace | |
static int *StaticFoo() { | |
static int val; | |
return &val; | |
} | |
inline int *InlineFoo() { | |
static int val; | |
return &val; | |
} | |
class Foo { | |
public: | |
static int *ClsFoo() { | |
static int val; | |
return &val; | |
} | |
}; | |
int *WeakSymbFoo() __attribute__((weak)); | |
int *WeakSymbFoo() { | |
static int val; | |
return &val; | |
}⏎ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clang++ -std=c++20 *.cpp -o a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "a.h" | |
#include <iostream> | |
static int _inited = []() -> int { | |
std::cout << "NS: " << NSFoo() << ", Static: " << StaticFoo() | |
<< ", Inline: " << InlineFoo() << ", Cls: " << Foo::ClsFoo() | |
<< ", Weak: " << WeakSymbFoo() << std::endl; | |
return 0; | |
}(); | |
int main() {}⏎ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NS: 0x1018c60e0, Static: 0x1018c60e4, Inline: 0x1018c60d0, Cls: 0x1018c60d4, Weak: 0x1018c60d8 | |
NS: 0x1018c60f0, Static: 0x1018c60f4, Inline: 0x1018c60d0, Cls: 0x1018c60d4, Weak: 0x1018c60d8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment