Access a function's return value in C++ scope guard

It is best to avoid accessing a function's return value in a scope guard or we need to be really careful about the return value's lifetime. Happy case Scope guard is a simple RAII concept in C++ that, in most cases, just works. struct ScopeGuard { ScopeGuard(std::vector& v): v_

When `__cxa_pure_virtual` is just a different flavor of SEGFAULT

A program crashed during shutdown, with message pure virtual method called which came from __cxa_pure_virtual – where a pure virtual function points to, in its vtable. Its implementation involves calling std::terminate which calls std::abort which by default throws a SIGABRT, and crashing the program. Now, why did…

Rust's early vs. late lifetime binding

Lifetime in many ways are similar to types but also different. The goal of this post is to explain my mental model of rust's lifetime binding works, when it takes place, and a trick to force late lifetime binding when needed. Here's a motivating example that I will use throughout…

zsh interprets a standalone redirect as a `cat` command

I use zsh and yesterday I was testing a program with myprogram 2>/dev/null. In one iteration, I accidentally copied a newline character after the myprogram command and the zsh prompt looked something like $ myprogram 2>/dev/null The program appeared to hang after printing out the expected output.…

C++ coroutine and lambda's lifetime

We rarely need to worry about lambda's lifetime more than any other objects in C++ until we are dealing with coroutine at the same time. folly's wiki has a good example of why we need to be careful about lambda's lifetime – https://github.com/facebook/folly/blob/main/folly/experimental/…

`folly::IOBuf` and zero-copy networking

I see folly::IOBuf often used as a return value (sub-)type in RPC definitions for data intensive and high performance applications. I looked at the code, and it says Well if it's used primarily for networking code, why do applications use it? I don't think people use sk_buff…

What I learned about `inline` recently

C++'s inline is pretty nice, in my opinion. I define an inline function with external linkage, things work as expected (https://en.cppreference.com/w/cpp/language/inline): * taking the address of the inline function works * function-local static objects work as expected (shared across all translation units) * no ODR…

`ssh` to my workstation over Internet

I have eero at home with eero plus subscription as I like the parental controls. To my delight, the subscription also comes with DDNS. I wanted to set it up so I can ssh to my workstation from a laptop from our town library or a coffee shop. 1. Enabled…