原创 What is the type of a constant in C? (U, UL, ULL, L, F)

Copied from here. When we write expressions like this in C: bool b = 1234567890 > 09876; What are the types of those

原创 ud2: illegal opcode, Undefined Instruction

Following is xv6 (rev11) chapter2 exercise 5,       Modify xv6 so that when a user program dereferences a null pointer,

原创 multithread: why main thread exit leads to other threads exit?

In linux multithread program, when main thread exit, other threads will exit too, why? How to keep other thread running

原创 memory cache 直接映射、全相聯映射和組相聯映射

cpu的執行速度很快,cpu從memory讀取數據速度很慢,導致cpu需要等memory,爲了提高cpu的效率,根據程序的局部性原理(現在訪問的數據很有可能以後還會訪問),引入了讀寫比較快的memory cache,cache用來存放剛剛

原创 The Buddy System Algorithm

目錄 1. Why need the Buddy System Algorithm 2. What's the Buddy System Algorithm 2.1 how to find buddy 3. Code implementa

原创 switch_to() in schedule()

Reading ULK about switch_to(prev, next, last), it's quite hard to understand why the need for the 3rd argument. It turn

原创 pass flags to make implicit rules

The built-in implicit rules use several variables in their recipes so that, by changing the values of the variables, yo

原创 程序輸出

1. copy from blog main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)(&a+1); printf("%d,%d",*(a+1),*(ptr-1)); } 輸

原创 Type conversions

All come from section 2.7 of the c programming language 2nd edition. BTW, this book is highly recommended for learning

原创 thread: detached state

與其被稱爲state,可能稱爲flag更合適些,因爲detached state並不是thread生命週期中的一個state(例如,running),而是一個flag,用來告訴OS當thread退出的時候,是否需要回收thread的res

原创 why not 'switch case' accept float point in condition?

A switch case example as below. The expression used in switch must be integral type ( int, char and enum). Any other ty

原创 malloc(0) & free(NULL)

man malloc / man free The  malloc()  function  allocates size bytes and returns a pointer to the allocated memory.  The

原创 c sort function in library: qsort()

目錄 qsort() in C library example reference qsort() in C library Usually sort is the first step for an algorithm. In C, t

原创 static variableS with same name

1. 多個c文件,每個文件都包含static int a; 2. 一個c文件中,有一個全局static int a;,在某個函數中,也有一個相同定義static int a; 這兩種情況都是合法的,另外這些變量a都是存放在同一個data段

原创 c struct bitfield (結構體位域)

兩篇非常棒的文章。 1. 再談c語言位域 2. Section bitfields 簡要總結一下: C99 guarentees that bit-fields will be packed as tightly as possible,