Simon Zimmermann: c

2010-01-10

Pointers

I’m taking a course on data structures and algorithms this spring. It’s thought in Java - using Robert Lafore’s Data Structures & Algorithms in Java. The book is ok for a IS student, as my self. It leaves out the math, but explains the different concepts in a orderly fashion. Since the code examples in the book are so bad it makes a good practice for the reader to re-write them as well.

As a challenge I’m trying to re-write the algorithms to generic c functions and structures instead. Since they don’t teach c here at the uni, it’s up to my self. I’m using K&R as a reference and C Programming: A Modern Approach by K. N. King when I need more examples or up-to-date stuff.

In the beginning, when writing generic c functions, the biggest challenge is really to not get lost in pointer/array arithmetics. Once you slowly, after many fail and errors, begin to get a grasp of the c-way of doing things - it’s real beauty.

If varr is a void array which in reality maybe is a char array, and elm_size is sizeof(char ), then (char )varr + 0 * elm_size is just a pointer to the first element in the array. And we could use a sentence like this to get to the first elem of that array; (char )((char )varr + 0 * elm_size). The concept of pointers is very simple. But it’s just as simple to at point the wrong memory-space; (char )((char *)varr + 0 * elm_size) for example.

I’m pushing code to my algorithms repository at github.com.

2010-01-10

Memmove Or To Cpy

2009-12-21

Generic C Programming