Skip to content

Instantly share code, notes, and snippets.

View eugnsp's full-sized avatar

Evgeny eugnsp

  • Raleigh, NC
View GitHub Profile
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active October 15, 2025 20:35
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@ar-pa
ar-pa / BigInt.cpp
Last active August 11, 2025 06:54
bignum class for C++
// In the name of Allah.
// We're nothing and you're everything.
// Ya Ali!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 14, lg = 15;
@carlchen0928
carlchen0928 / simple_threadpool.cpp
Last active June 17, 2019 20:36
Simple thread pool. Don't support user wait all task done.
#include "join_threads.h"
#include "threadsafe_subtle_queue.cpp"
#include "threadsafe_exceptionsafe_queue.cpp"
#include <thread>
#include <vector>
#include <atomic>
/*
* Simplest thread pool implementation, exception safe.
* Don't support user wait all task finish.
@carlchen0928
carlchen0928 / spinlock_mutex.cpp
Created June 29, 2015 02:52
c++ spinlock && test with mutex
#include <atomic>
/*
*
* spin lock implemented by C++ std::atomic
*
*/
class spinlock_mutex
{
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>