C++ - Chapter 4: Function

Functions Functions are self-contained blocks of code designed to perform specific tasks. They promote code reusability, modularity, and abstraction. Functions can participate in polymorphism through: Compile-time polymorphism (Static Polymorphism) Function overloading Operator overloading Function templates Runtime polymorphism Virtual functions 1. Function Overloading Function overloading allows creating multiple functions with the same name but different parameter types or parameter counts. Different return types alone are not enough to overload a function. Function delete using delete keyword. Default-arguments is a default value provided for a function parameter. Parameters with default arguments must always be the rightmost parameters, and they are not used to differentiate functions when resolving overloaded functions. void print_int(int x) {} void print_int_or_default(int x, int y = 2) {} template <typename T> void print_int(T) = delete; void main() { print_int(97); // okay // printInt('a'); // compile error // printInt(true); // compile error print_int_or_default(5); // prints: 5, 2 print_int_or_default(5, 10); // prints: 5, 10 } 2. Operator Overloading Operator overloading allows C++ operators to be customized for user-defined types. ...

May 24, 2026 · 7 min · Phong Nguyen

C++ - Chapter 5: Data Types

Data Types A data type defines the kind of value a variable can store, how much memory it uses, and what operations can be performed on it. 1. Type Conversion Type conversions │ ├── Implicit conversions (compiler performed automatically) │ │ │ ├── Numeric promotions │ │ ├── bool -> int │ │ ├── char -> int │ │ └── float -> double │ │ │ └── Numeric conversions │ ├── Widening conversions │ │ ├── int -> long long │ │ └── int -> double │ │ │ └── Narrowing conversions │ ├── double -> int │ ├── int -> char │ └── long long -> int │ └── Explicit conversions (casts) ├── static_cast<T>(expr) ├── dynamic_cast<T>(expr) ├── const_cast<T>(expr) ├── reinterpret_cast<T>(expr) └── (T)expr ///< C-style cast 1.1 Implicit Implicit type conversion is performed automatically by the compiler when an expression of some type is supplied in a context where some other type is expected. ...

May 24, 2026 · 6 min · Phong Nguyen

C++ - Chapter 6: Pointer and Reference

Pointer and Reference lvalue/rvalue An lvalue is an expression that refers to an identifiable object, function, or bit-field. It has an address that can be taken and typically persists beyond a single expression. An rvalue is an expression whose primary purpose is to provide a value rather than identify an object. e.g. temporary objects and literals An lvalue can generally be used wherever an rvalue is expected because its value can be read. ...

May 24, 2026 · 11 min · Phong Nguyen

System C TLM 2.0

SystemC - TLM Transaction-Level Modeling 2.0 (TLM-2.0) is a modeling methodology defined in IEEE 1666-2023. Instead of communicating through individual signals at every clock cycle, modules exchange complete transactions (read/write requests) using C++ function calls. This raises the abstraction level, dramatically increasing simulation speed and enabling early software development before RTL is available. 1. Introduce TLM-2.0 replaces pin-level signal connections with high-level function calls carrying a tlm_generic_payload transaction object. An initiator (e.g., a CPU model) calls transport functions on a target (e.g., a memory) through typed sockets and a bus/router. ...

March 29, 2026 · 12 min · Phong Nguyen

System C

System C SystemC is a C++ class library, that provides a mechanism for managing complex systems involving large numbers of components. SystemC is capable of modeling hardware and software together at multiple level of abstraction (Algorithm / Functional level, Transaction-Level Modeling, Register Transfer Level) Modeling is the process of creating a simplified version of a real system. Simulation is the process of executing the model over time to see how it behaves. ...

March 23, 2026 · 21 min · Phong Nguyen

CMake Notes

1. Introduction CMake is a tool used for meta-build system generator. We write high-level instructions in a CMakeLists.txt file (platform-agnostic).Then CMake generates build system files for the platform we choose: On Linux/Unix: generates Makefile (for make) or build.ninja (for ninja). On Windows: generates Visual Studio solutions (.sln). On macOS: can generate Xcode projects. CMake Generators: CMake support multiple build systems output a.k.a generators. Which generator is used can be controlled via CMAKE_GENERATOR or cmake -G option ...

August 21, 2025 · 14 min · Phong Nguyen

Cpp

See plus plus :) . Refer Introduce Fundamentals String 21.8. Printing inherited classes using operator« Refer to the learncpp.com ## 23. I/O ### 23.1. I/O Streams - It is a part of the STL. - I/O is implemented with `streams`. <br> - **stream** is a sequence of bytes that can be accessed sequentially. It may produce or consume amounts data over time. - **input stream**: used to hold input data from a data producer. - **output stream**: used to hold output data for a particular data consumer. - *e.g.* when writing/input data to an device, the device may not be ready to accept that data, so the data will sit in the stream. - [C++] <=> streams <=> [os] <br> - **I/O in C++**: we can use the STL classes to deal with streams - **input stream**: `istream` & extraction operation (`>>`) is used to remove values from the stream - **output stream**: `ostream` & insertio operation (`<<`) is used to put vlaues in the stream.\ - `iostream` can handle both i & o <br> - **Standard streams**: - `cin`: an `istream` object tied to the standard input - `cout`: an `ostream` object tied to the standard output - `cerr`: an `ostream` object tied to the standard error - unbuffered output - `clog`: an `ostream` object tied to the standard error - buffered output ### 23.2. Input with istream - Use `extraction operator (>>)` to read information from an input stream. It skips **whitespace (blanks, tabs, and newlines)**. Use `get(), getLine()` to not discard the whitespace. - `manipulator` is an object that is used to modify a stream when applied with the `extraction (>>)` or `insertion (<<)` operators. <iomanip> ### 23.3. Output with ostream https://www.learncpp.com/cpp-tutorial/output-with-ostream-and-ios/ ### 23.4. Stream classes for string <sstream> - String streams provide a buffer to hold data but are not connected to an I/O channel. - The primary uses of the string stream: - Display data later then or proccess i/o data. - Get data into a string stream - Get data from a string stream - Convertion strings/numbers - Clear a string stream - e.g: ```cpp #include <sstream> #include <string> int main() { std::stringstream os{}; // input os << "0xF"; std::cout << os.str(); os.str("0x1 0x2"); std::cout << os.str(); // output std::string bytesStr = os.str(); std::cout << bytesStr; os.str("0x0 0xF 0xE 0x2"); os >> bytesStr; std::cout <<bytesStr; // conversions int byte_low = 0xFFF; int byte_high = 0x001; os.clear(); os << byte_low << ' ' << byte_high; std::cout << os.str(); } 23.5. Validation https://www.learncpp.com/cpp-tutorial/stream-states-and-input-validation/ ...

February 9, 2025 · 5 min · Phong Nguyen

Makefile Guide

Introduction It’s a build tool (specifically, make is a build automation utility). How it works: Reads a file called Makefile that describes rules for how to build source files into targets (executables, libraries, etc.). GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program’s source files. Make get its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from the other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program. ...

August 9, 2024 · 11 min · Phong Nguyen

Git Notes

Git Cheat Sheet <commit> can be any Git reference that points to a commit Local git config: .git/config (See all possible config options man git-config) Global git config: ~/.gitconfig Git ignore file : .gitignore Local ignore rules (not committed): .git/info/exclude # Start a new repo $ git init # clone an existing repo $ git clone <url> # Add untracked file or unstaged changes $ git add <file> # Add all untracked files and unstaged changes $ git add . ### Choose which parts of a file to stage $ git add -p # Delete file $ git rm <file> # Tell Git to forget about a file without deleting it $ git rm --cached <file> # Unstage one file git reset <file> # Unstage everything git reset # Check what you added git status # Make a commit (and open text editor to write message) git commit # Make a commit git commit -m 'message' # Commit all unstaged changes git commit -am 'message' # Make an empty commit for specific purpose git commit --allow-empty -m 'message' # Switch branches $ git switch <name> $ git checkout <name> # Create a new branch from the current branch $ git switch -c <new-branch> $ git checkout -b <new-branch> # Create a new branch from another local branch $ git switch -c <new-branch> <base-branch> # prefer $ git checkout -b <new-branch> <base-branch> # Create a new branch from a remote branch $ git switch -c <new-branch> origin/<remote-branch> # prefer $ git checkout -b <new-branch> origin/<remote-branch> # List branches $ git branch $ git branch -r # remote branches # Delete a branch $ git branch -d <name> $ git branch -D <name> # Force # Diff all staged and unstaged changes $ git diff HEAD # Diff just staged changes $ git diff --staged # Diff just unstaged changes $ git diff # Save to file $ git diff >> file # Compare two refs and list changed files git diff --name-only <branch> <commit> > files.txt # Show diff between a commit and its parent git show <commit> # Diff two commits git diff <commit> <commit> # Diff one file since a commit git diff <commit> <file> # Show a summary of a diff git diff <commit> --stat git show <commit> --stat # Discard unstaged changes in one file git restore <file> git checkout -- <file> # Discard all changes (staged and unstaged) in one file git restore --staged --worktree <file> git checkout HEAD -- <file> # Delete all staged and unstaged changes git reset --hard # Force Delete untracked files/director git clean -fd # 'Stash' all staged and unstaged changes git stash # "Undo" the most recent commit git reset HEAD^ # Squash the last 5 commits into one git rebase -i HEAD~6 # Open the log history git reflog git reflog BRANCHNAME # Move current branch back to <commit> git reset --hard <commit> # Recreate the branch using hash git checkout -b <new-branch> <commit> # Change a commit message / add a file git commit --amend # Show commit history git log main # Show compact commit history git log --oneline main # Show commit history as a branch graph git log --graph main # Show a compact graph of all branches git log --oneline --graph --all --decorate # Show every commit that modified a file git log <file> # Show every commit that modified a file, including before it was renamed git log --follow <file> # Find every commit that added or removed some text git log -G "<text>" # Show who last changed each line of a file git blame <file> # Cherry pick to copy one commit onto the current branch git cherry-pick <commit> # Replace the current version of a file with the version from another commit git restore --source <commit> <file> # Add a Remote git remote add <name> <url> # Push the main branch to the remote origin git push origin main # Push the current branch to its remote "tracking branch" git push # Push a branch that you've never pushed before git push -u origin <name> # Force push git push --force-with-lease # the remote has not changed git push --force # Create a tag $ git tag <tag> $ git tag -a <tag> -m "<des>" # Push tags $ git push origin <tag> $ git push --tags # Fetch changes git fetch origin main # Fetch changes and then rebase your current branch git pull --rebase # Set a config option git config user.name <user_name> git config user.email <user_email> # Set option globally git config --global ... # Mark a repository as safe (useful with Docker, WSL, shared folders, etc.) $ git config --global --add safe.directory <path> # Initialize and update submodules git submodule update --init # Run a single Git command without SSL certificate verification $ git -c http.sslVerify=false <git-command> $ git config --global http.sslVerify false # Set upstream branch git branch --set-upstream-to=origin/<branch_name> # Copy a file from another branch without switching branches git checkout <branch> -- <file> # Verify the connect to the remote $ git ls-remote origin # Remove cached credentials $ git credential reject <<EOF protocol=https host=<> EOF Useful VSCode Extensions Git Graph Git History Useful Eclipse Plugins EGit TBD

May 30, 2026 · 5 min · Phong Nguyen

C/C++ Tools

1. Doxygen Code documentation can be achieved with the Doxygen framework which is one of the most standard one for many languages. 1.1. Getting Started Install: $ sudo apt install doxygen Create a config and update: $ mkdir docs && cd docs $ doxygen -g Doxyfile $ vi Doxyfile Running doxygen: $ cd docs && doxygen <config-file> & htlm/index.htlm Install the VSCode Extension: Doxygen Documentation Generator 1.2. Doxygen with CMake Create a Doxygen file template for CMake: ...

March 30, 2026 · 4 min · Phong Nguyen