Skip to content

Instantly share code, notes, and snippets.

View glouw's full-sized avatar

Gustav Louw glouw

View GitHub Profile
@fay59
fay59 / Quirks of C.md
Last active January 23, 2024 04:24
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@Aegean-Homines
Aegean-Homines / HashFunctions.h
Last active January 18, 2022 18:21
Different Hash Functions (thanks to Prof. Volper)
/*
COMPARISON
keylen = 512, iterations = 100000
====================================
Simple... 0.078 s
RS... 0.422 s
RS (Fast)... 0.156 s
Universal... 0.454 s
Universal (Fast)... 0.156 s
PJW... 0.328 s
@XProger
XProger / blend.cpp
Created October 14, 2014 20:33
Fast integer alpha blending
uint32 blend(uint32 color1, uint32 color2, uint8 alpha) {
uint32 rb = color1 & 0xff00ff;
uint32 g = color1 & 0x00ff00;
rb += ((color2 & 0xff00ff) - rb) * alpha >> 8;
g += ((color2 & 0x00ff00) - g) * alpha >> 8;
return (rb & 0xff00ff) | (g & 0xff00);
}