Peter Mawhorter
Short answer: the compiler handles this for us.
gdb
and valgrind
)Write your questions on the boards.
Component | Inputs | Outputs |
---|---|---|
PC |
|
|
Instruction Memory |
|
|
Control Unit |
|
|
Register File |
|
|
Arithmetic Logic Unit (ALU) |
|
|
Data Memory (RAM) |
|
|
BEQ Logic |
|
|
if
/while
/catch
/etc. ≈ BEQ ±
JMP#include <stdio.h>
gets
you printf
Prints:
%
creates a hole, letter specifies what kind
DON’T BE FOOLED
IN C THERE ARE ONLY POINTERS
*
operator to dereference it and talk
about what’s at that address (can both read & write there)&
operator to get the address of something
which can be stored in a pointerint *p
, p + 1
is 4 bytes
farther)void *
when we don’t know what we’re pointing
toint vec[]
is really just int *vec
char *
Prints:
Declare a variable x
of type “array-of-int”
Actually: type int *
, or
pointer-to-int
Put the numbers 1, 2, 3 into that array
Actually: allocate space for three numbers as part of
the program, and store the address of the first one in
x
Prints (%p
is the format for a pointer):
This is the memory address of the first number
Prints:
??? Addresses change each time you run it, for security
Prints:
*(x + 1)
??? Add 1 to address of x, get value there
int x[]
is really a
pointer int *x
[]
means unspecified size.x[2]
is really just
*(x + 2)
malloc
to ask for some bytesmalloc
sizeof
to figure out # of bytes based on # of
entries of a specific typevoid *
, we cast to what we need(type) value
)char *string = "Some words."
?char *string
char *
0x00
at end.
string.h
gdb
and valgrind
gdb
stands for “Gnu DeBugger”valgrind
after the gates of Valhalla
(“grinned,” not “grind”)gdb
gdb
to debug a C program compiled with -g:
valgrind
valgrind
‘memcheck’ mode to check for memory errors
during execution: