Lecture 2 Flashcards
GDB run does what?
Executes the program
gdb break does what?
set a breakpoint (a place for the program to stop)
gdb next
Run until the next instruction in this function(don’t follow function calls)
gdb step
Stop at the next instruction call anywhere (goes into function calls)
gdb continue
run until the next breakpoint
gdb print
show the value of a variable
gdb set
change the value of a variable
gdb jump
Start executing at a different line number
gdb enable/disable
enable or disable breakpoints
What is the standard format of a switch?
switch(class) { 1: report 1 2: report 2 3: report 3 }
What are the five ways to leave a loop iteration in c?
- Finish the code flow in the loop
- Continue-command that says to go to the next loop iteration
- Break-leave the current block of code
- Goto: has you redirect to a specific line of the program, identified by a label
- Return: leave the current function completely
Why are we discouraged from using goto?
To avoid ‘spaghetti code’.
What is a useful purpose of goto?
Is to jump to error code before leaving the function
Why do some style guides prefer having a single exit point for a loop or function?
Makes for easier debugging and understanding of when you have left the block of code
What do functions return?
A return statement
Do procedures also return a return statement?
Nope!
How should you aim to keep functions?
Small and with a well defined purpose
Can variables declared inside of a function or procedure be used outside of the function?
Nope!
What happens to values of variables once the function is complete
They disappear
How can you prevent variable values from disappearing once the function is complete?
Use a static variable
What are the four parts of a running program?
Executable code of the program
Global variables
Call stack
Heap
Which sections of the anatomy of a running program are created at compile time?
The executable code and the global variables
What type of data structure is the call stack?
LIFO; last in first out
When we call a function, what is created?
A stack frame
Where is the stack frame added once a function is called?
The call stack
What does a stack frame contain?
The instructions to execute in the calling function when the function ends
Hardware information that the current function will change and need to be restored for the calling function
The parameters for the function
Space for local variables for the function
What happens when the function ends?
The stack frame for the function is removed from the call stack, so all the information disappears.
What is always bottom of the stack?
Main local variables