Thursday, December 3, 2009

Device Drivers and UART

One of the classic step by step explanation of the device drivers is explained in the following linux journal

One of the classic explanation for UART is explained here

Wednesday, December 2, 2009

Void Pointers CANNOT be deferenced

A void pointer in C cannot b derefrenced, nor can any arithmetic operation be performed on it

It's mainly used in function prototypes to indicate a pointer whose type is only known at runtime.

So, one could write a trivial function to sort an array of ints:


int cmp_int(const void *a, const void *b);

int main(void)
int a[] = { 1, 5, 2, 9, 3};
size_t n = sizeof a / sizeof a[0];
qsort(&a, n, sizeof a[0], cmp_int);
for (i=0; i < n; i++)
printf("%d\n", a[i]);

int cmp_int(const void *a, const void *b)
const int *f = a;
const int *s = b;

/* Here, one cannot perform *a < *b */
if (*f < *s) {
return -1;
} else if (*f > *s) {
return 1;
} else {
return 0;