Lec14_notes

advertisement
1. Slide
 How many have not programmed in C? You’re screwed!
2. Slide
 Show basic compiling process
 Show what Java is like. (Really, it’s compiled AND interpreted.) Take a .java file, “compile it”
into .class file – byte code.
o The byte code is interpreted as needed.
 Why slower?
o Needs to be translated into machine instructions as the program is running.
 Why not as slow as it used to be?
o Advances in interpretation lead to compiling some stuff in advance of running. The
interpreter looks ahead and compiles code into machine language.
 So why interpret? Ex: Java
o Show how byte code is platform independent for any machine having a JVM
 Windows, Unix, Mac, Android (not exactly, but…)
 When we talk about compiled languages, we mean “traditionally compiled”. There’s no reason
you can’t take C code and interpret it (convert to machine instructions on the fly).
3. Slide
 If x is not used later, and y is not used later, a “smart” compiler will not use them. It will just do
z = 8*w and print that value to the screen.
 A “dumb” interpreter will just interpret the lines one by one. A “smart” interpreter will be able
to “look ahead”
4. Slide
 When we do a “gcc”, all this gets done.
 Show example of conditional compilation:
o #ifdef DEBUG…#endif
o #ifdef 0, #ifdef 1
 The assembler is part of the compiler
 Why do Library Object Files go directly to the Linker?
5. Slide
 Show an example of looking at the assembly language.
 Would it be different if done on a different machine?
o Do on unix machine, then on my local machin
6. Slide
 This slide is just showing some differences between Java and C
 Many of the slides ahead were meant to show differences between C and Java. Previous 101
courses were taught in Java, so some students did not know C.
7. Slide
 Show what happens when you do a #include
o First, what would be in stdio.h (prototypes for printf, scanf, etc.)
o Those are pasted at the top of your file by the preprocessor.
8. Slide
9. Slide
 argc and argv used for “command line arguments” – more later
o notation looks confusing!
10. Slide
 Brief intro to pointers – draw some pictures of array and pointers. MUCH more later.
11. Slide
 Point out hex, exponential, ASCII characters
12. Slide
 You may not have seen these before. Operate on a BIT level.
 When you have an integer, it’s really stored as a sequence of bits
o Show a couple examples (<<, ~, etc.)
13. Slide
 You know this already - reference
14. Slide
 Reference
 Actually, do worry about the & - it means “address of”
15. Slide
 Reference, note the %x
 Can also do %p, %i, %b
16. Slide
17. Slide
18. Slide
19. Slide
Slide – static variables
Slide – static variables
Slide
 Why Globals are bad
o Makes code very hard to read (when projects get large)
 Hard to figure out which functions change global variables
o Anyone (the writer of some other module) can change the value of the variable, and
maybe you don’t want that. (Similar to private data in OO languages)
o A variable name can only be used once (can be a problem in larger projects)
o Requires more memory because they always exist, as opposed to locals that “go away”
20. Slide
 We will get to the specifics of this later, starting in the next lecture.
21. Slide
 Picture is valid for all programs, the specific registers used to keep track of the data sections is
specific to the LC-3
22. Slide
Download