Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


uires that the user never ask for more
What if we set indexps = 50? The
rray and the 25 bytes of RAM
sn’t allocated to this function
of knowing what’s supposed to be stored there, but we overwrite

rray size
s

, EEPROM_START + 1);

rror ssag

o why bother adding
he code size and is a
make will often be

FIFOs and LIFOs: Stacks and Queues (Circular Buffers)


ers frequently use the stack when calling
routines and running algorithms.

acks
shwas
ttom trays never get used. It is important to us that the we never try to use the
aks down and
C uses a stack
fo’ to refer to these kinds of

This is a perfectly good function, but it req
bytes than the size of the pBuffer array.
LoadEEPROM will fill the Name[STRLENGHT] a
that follow the array. Since the second 25 bytes wa
we have no way
it anyway and almost certainly cause havoc.


It would be good programming practice to add a line that checked the a
and the number of bytes before calling the LoadEEPROM function, and if there’
a problem generate an error.


if(NAMESIZE >= indexps){
// Load name from EEPROM
LoadEEPROM(Name, indexps
}
else
E Me e(“LoadEEPROM error: number of bytes requested >
array size”);


But we are smart and we’d never make such a dumb error, s
the extra code that only slows things down and increases t
pain to type? The obvious answer is that the mistakes we
painfully dumb.


FIFOs and LIFOs:


Stacks
Assembly language programm
sub


St are like those piles of trays in cafeterias, we take trays off the top and the
di her piles them back on the top. The top trays are usually wet and the
bo
tray below the bottom tray because it doesn’t exist, the analogy bre
we have a blown stack, as shown earlier when we discussed how
when calling functions. Sometimes you’ll see ‘fi

Free download pdf