Einstein wrote:
Just a silly question as I'm not much at home in advanced C-programming: why does pointers in C need to be declared as certain types ? I figure this is a compiler-directive to have access to the different offsets in the varibales/structures/functions, am I correct ? :-?
That's about it, really. At a machine level, pointers are just addresses. In the 680x0 for example, a pointer can be any 32-bit value. You usually have to care about the size of the element pointed to when modifying them.
In (slightly) higher level languages such as C, you define a pointer as pointing to a particular type. This can be anything , from a byte to a complex structure.
For example, assuming we have 32-bit integers;
int x;
int myInt[4] = { 0, 1, 2, 3 };
int *pInt = &myInt[1]; /* points to the second integer in the array */
C then takes care to correctly do the maths when you operations like
x = *(++pInt); /* x = 2 */
x = *(--pInt); /* x = 1 */
x = pInt[2]; /* x = 3 */
On a system with 32-bit integers and 32-bit pointers, the actual value of pInt would be changing by 4 when you use ++/-- and the index scaled by 4 when you use [].
Having typed pointers also helps to prevent many problems that could otherwise arise when dealing with structures etc. The compiler can see the definition of a structure and can therefore ensure that the -> operation can only access the defined members of that structure.
The void pointer was introduced to deal with the requirement of uninitialised/undefined memory. The void pointer is purely designed to simply hold the address of something and does not allow dereferencing or arithmetic of any kind (since no information about the thing pointed to is known).