Miscellaneous

Also, do realize that it's a bug to attempt to use just a pointer to access memory unless the memory has already been allocated. Remember that pointers have no memory; they have to be allocated memory (either statically at compile time or dynamically at runtime).

For example, one writes a C function that uses the parameter as a return valuea common C programming trick (these are often called value-result or in-out parameters):

unsigned long *uptr; [...]     my_awesome_func(uptr); // bug! value to be returned in 'uptr'[...]

This is a bug; the uptr variable is just a pointerit has no memory. One way to fix this is as follows:

unsigned long *uptr; [...]    uptr = malloc(sizeof(unsigned long));    if (!uptr) { [...handle the error...] ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.