Skip to content

Instantly share code, notes, and snippets.

View raalkml's full-sized avatar

Alex Riesen raalkml

View GitHub Profile
@raalkml
raalkml / smiley.c
Created September 18, 2012 07:52 — forked from anastasop/smiley.c
smiley.c
// the smiley program demonstrated by Russ Cox at http://research.swtch.com/acme
// it shows that the plan9 compiler http://plan9.bell-labs.com/sys/doc/comp.html fully supports UTF-8
// i tried to compile it with a recent version of the plan9 compiler running on vmware but it failed.
// it seems that older versions of the compiler supported sizeof(void) == 0
// anyway you get the idea
#include <u.h>
#include <libc.h>
@raalkml
raalkml / insane_kernel_macro_solution.c
Created April 12, 2012 09:48 — forked from hank/insane_kernel_macro_solution.c
The solution to Linus' question on resolving undefined macros in the preprocessor to 0, as well as resolving defined macros to their values.
#include <stdio.h>
#define CONFIG_FOO 1
#define CONFIG_NOO 0
#define is_set(macro) is_set_(macro)
#define macrotest_1 ,
#define is_set_(value) is_set__(macrotest_##value)
#define is_set__(comma) is_set___(comma 1, 0)
#define is_set___(_, v, ...) v
//
// A template for a dynamically reallocated bitmap of unsigned values, each
// the given number of bits long. An array of bit(s)-sized elements.
// The remainder of division of sizeof(unsigned) by elem_size must be 0 (to
// simplify code and avoid operations on split elements of bitarray::bits).
// The place of bits pointer is reused to minimize initial allocations.
//
#ifndef _BITARRAY_HPP_
#define _BITARRAY_HPP_
/* bitmaps and bitmap operations */
#ifndef _BITMAPS_H_
#define _BITMAPS_H_
/*
* Bitmaps are arrays of unsigned ints, filled with bits in most-
* significant-first order. So bitmap[0] shall contain the bits from
* 0 to 31 on a 32bit architecture, bitmap[1] - 32-63, and so forth.
*
* The callers are responsible to do all the bounds-checking.