Skip to main content

Posts

Showing posts from 2024

How to use gdb in Ubuntu Terminal

Here's a practical, minimal guide for using GDB in Ubuntu terminal — from launching to setting breakpoints and navigating your code. 🧰 Step 1: Compile with Debug Symbols Use -g and disable optimizations ( -O0 preferred for debugging): bash Copy Edit g++ -g -O0 -o myprog myprog.cpp 🚀 Step 2: Launch GDB bash Copy Edit gdb ./myprog You'll see a (gdb) prompt. 🎯 Step 3: Set Breakpoints You can set breakpoints in three main ways : ✅ a. At a function gdb Copy Edit (gdb) break main ✅ b. At a specific file and line gdb Copy Edit (gdb) break myprog.cpp:42 ✅ c. At a method in a class gdb Copy Edit (gdb) break MyClass::doSomething If the symbol is mangled (C++), GDB usually demangles automatically, especially if compiled with -g . ▶️ Step 4: Run the Program gdb Copy Edit (gdb) run 🧭 Step 5: Navigate Command Meaning next or n Step over current line step or s Step into function call finish Run until current function returns continue or c Continue until...

libzip, libcurl, libwebsockets, jansson json, gsl what other good libraries in C? (chatGpt discussions)

libzip, libcurl, libwebsockets, jansson json, gsl what other good libraries in C? ChatGPT said: ChatGPT Here’s a list of other useful libraries in C, categorized by their purpose, that can complement the ones you mentioned: 1. Networking and Protocols libuv : A multi-platform asynchronous I/O library, used for network operations and file system interactions. Powers Node.js. asio : While more known in C++, it has a C API for network programming (TCP, UDP, etc.). libevent : Provides asynchronous event notification for network services and supports multi-threading. ZeroMQ : High-performance asynchronous messaging library for building scalable distributed systems. 2. Compression and Archiving zlib : A popular and highly efficient compression library. bzip2 : Another compression library, focused on higher compression ratios than zlib . LZ4 : An extremely fast compression library, optimized for speed rather than compression ratio. zstd (Zstandard) : A fast and efficient compression algorithm...

C/C++ Postgres libpq execute query with params chatGpt example

PGresult *PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char * const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat); give example ChatGPT said: ChatGPT Here’s a basic example demonstrating how to use PQexecParams in C++ to execute a parameterized query in PostgreSQL. Example: Inserting Data Using PQexecParams Let's assume we are inserting a row into a table called users with the following columns: id (integer) name (text) age (integer) cpp Copy code # include <iostream> # include <libpq-fe.h> # include <memory> # include <string> void checkResult (PGresult* res, PGconn* conn) { if ( PQresultStatus (res) != PGRES_COMMAND_OK) { std::cerr << "Execution failed: " << PQerrorMe...