This file contains hidden or 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
int main() { | |
Mammal *m; | |
if (rand() % 2) { | |
m = new Cat(); | |
} else { | |
m = new Dog(); | |
} | |
m->walk(); | |
delete m; |
This file contains hidden or 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 <cstdlib> | |
#include <iostream> | |
struct Mammal { | |
Mammal() { std::cout << "Mammal::Mammal\n"; } | |
virtual ~Mammal() { std::cout << "Mammal::~Mammal\n"; }; | |
virtual void run() = 0; | |
virtual void walk() = 0; | |
virtual void move() { walk(); } | |
}; |
This file contains hidden or 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
# Compile c++ to llvm bytecode | |
clang++ -S -emit-llvm -o bytecode.ll $1 | |
# Convert bytecode to C | |
llc -march=c -o code.c bytecode.ll | |
# 'fix' static inline. This is a workaround for a bug | |
# in one of the parsers, I think. | |
sed -i 's/static inline.*//' code.c |
This file contains hidden or 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
template<typename T> | |
class Foo { | |
public: | |
Foo() { | |
++c; | |
} | |
private: | |
thread_local static int c; | |
}; |
This file contains hidden or 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
num test_enum | |
{ | |
A, | |
B, | |
C | |
}; | |
template<test_enum T> | |
int f(int x); |
NewerOlder