Skip to content

Instantly share code, notes, and snippets.

@GENHEN
Last active February 3, 2018 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GENHEN/3338b37092aaf9358c1e54a7f0a1c3f1 to your computer and use it in GitHub Desktop.
Save GENHEN/3338b37092aaf9358c1e54a7f0a1c3f1 to your computer and use it in GitHub Desktop.
/*
run (bash or cygwin-on-windows):
g++ -O3 -std=c++14 -o test.exe test.cpp && ./test.exe; rm ./test.exe
run and print exit code (bash or cygwin-on-windows):
g++ -O3 -std=c++14 -o test.exe test.cpp && ./test.exe && echo "$?"; rm ./test.exe
time (bash or cygwin-on-windows):
g++ -O3 -std=c++14 -o test.exe test.cpp && time ./test.exe; rm ./test.exe
assembly code (bash or cygwin-on-windows):
g++ -O3 -std=c++14 -o test.o -c test.cpp && objdump -d test.o
g++ -O3 -std=c++14 -o test.o -c test.cpp && objdump -M intel -d test.o
*/
#include <algorithm>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
class foo
{
public:
int *p;
};
int main()
{
foo x;
x.p = new int;
*(x.p) = 4;
// I never defined move() :D
// now foo y has the same pointer,
// and if x goes out of scope,
// y still points to original pointer
foo y = move(x);
printf("num y is pointing to: %d\n", *(y.p));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment