Go to file
Alexis Pereda 44b8a07a42 update README.md 2020-03-26 10:57:52 +01:00
examples/et [et] lambda/curry 2019-08-14 16:40:58 +02:00
.gitignore initial commit 2019-07-02 16:35:02 +02:00
CMakeLists.txt initial commit 2019-07-02 16:35:02 +02:00
README.md update README.md 2020-03-26 10:57:52 +01:00

README.md

Purpose

The purpose of this repository is to provide code examples that can be compiled and run for people reading my PhD thesis. These examples codes are not for production and often are simplified with regard of technical specificities (for example, but not limited to, perfect forwarding).

Usage

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

then run any example binary, located inside the build/examples/ directory.

Remarks

Assembler code

Some examples are meant to show the assembler code they generate. To see that, one can use for example https://godbolt.org/ or objdump or GDB. As objdump cannot only dump a specific function, here is the GDB version:

gdb -batch -ex 'set disassembly-flavor intel' -ex 'set print asm-demangle on' -ex 'disassemble main' "${program_to_execute}"

One can create an alias to ease the usage of GDB:

alias disas="gdb -batch -ex 'set disassembly-flavor intel' -ex 'set print asm-demangle on' -ex 'disassemble main'"
disas "${program_to_execute}"

Important note: if using cmake to produce the Makefile, you must call it with at least:

cmake -DCMAKE_BUILD_TYPE=Release ..

or the examples will be compiled without the optimization level 2.

use of volatile

When a value is required to show something, it is necessary to prevent the compiler to optimize out this value. To achieve this, one can read the value from a file, for example, but it will generate more assembler code. Another solution is the volatile type modifier that forbids optimization like caching or other optimizations like:

int main() {
	int volatile v0 = 5, v1 = 7;
	return v0 + v1;
}

Without volatile, the addition is done by the compiler and main returns directly 12. With volatile, the generated assembler code will contain an add instruction, even with -O2.

std::printf instead of std::cout

C++ iostreams cause lots of assembler code, for that reason, when an example is expected to be possibly used by looking at its generated assembler code, iostreams are avoided and replaced by printf.