10. Pointers

10.1. Motivation and plan

Understanding pointers in C is very important:

  • Using pointers from a high level language like C allows you to understand how your program is being executed in the computer’s hardware.

  • Advanced programming in C involves the use of pointers, and using them effectively is important.

  • Programming embedded systems involves accessing specific memory locations which are mapped to hardware functionality. Writing to those memory addresses can configure a peripheral device or transmit data, and reading from these memory addresses can receive data or give status on the device.

Our plan is to become more familiar with pointers in C and with the layout of memory on our computers.

You might have access to a Raspberry pi or another device which you can program to access hardware locations. A link for this is:

http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/

Or you might not have an embedded system available, and that will give us the opportunity to simulate a sample piece of real hardware.

This kind of simulation work is an important type of programming, and a type that few programmers know how to do.

We will start with a quick review of some basic C programming techniques that use pointers and create situations where we we copy chunks of memory.

Then we will have a quick review of

10.2. What are pointers?

10.3. Basic pointer code: strings and memory copy

strings…

memcpy for big structures

10.4. Linked lists

self-referential structures

10.5. A review of bitwise operators

10.6. Simulating a hardware device