CPP cast

Intro Casting in C++ is a way to convert a value from one data type to another. There are four casting operators in C++, each serving different purposes and with different levels of safety and functionality. This paper will introduce when and how to use them with examples. std::static_cast cppreference explanation It is the most commonly used cast in C++. It is used for conversions between compatible types, you can think of it as converting between basic c++ types. Such as int, float, double. You can use it convert integer to any enum type. ...

February 20, 2024 · 3 min · 441 words · Croak

Gdb quick start

Intro This paper will introduce you how to quickly use gdb GDB Commands Debug program Debug program with gdb is very simple, just follow below steps Build your program with debug info gcc {your options} -o0 -g3 -ggdb Start gdb # without args gdb {program} # with args gdb --args {program} {args...} Add breakpoints (gdb) b {filename}:{line} # for example (gdb) b test.cc:20 # the gdb will auto find file by filename and program debug info # if gdb can't find file, add file search dir (gdb) dir {filepath} Run program and debug # In gdb command line (gdb) run # when program reach one breakpoint, you can print symbol (gdb) print {symbol name} # even with object's function, such as (gdb) print list.size() Debug coredump file Core file can help us analysis program coredump reason. (TODO) ...

February 20, 2024 · 2 min · 271 words · Croak

Create conan package by conan-center-index

This papar based on conan 1.x Intro The conan-center-index contains a lot of recipes. If you want to build everything from scratch or create conan packages on your local conan repo, you can use this recipes. Assuming you already have some knowledge of conan and build your own conan package based on conan docs. The conan tutorial tell you import a prebuild package like below conanfile.txt style [requires] poco/1.9.4 conanfile.py style requires = ["poco/1.9.4"] # or self.requires("poco/1.9.4") Somehow, your want to build your packege with specific conan settings, such as cross-compile, with debug info and so on. ...

February 19, 2024 · 2 min · 369 words · Croak