CS 330 Lecture 19 – A Type Dichotomy
Agenda
- what ?s
- system vs. programmer-defined
- strong vs. weak
- static vs. dynamic
TODO
For a 1/4 sheet participation point, compose a midterm question about some topic we’ve discussed so far this semester. Follow these guidelines in forming your question:
- The question should require cognitive processes to answer. Merely recalling trivia does not. You can look at exams from past semesters under the Teaching tab.
- The question should be short and accessible.
- The question relate to the course objectives, which are:
- Recognize and exploit the strengths of three major programming paradigms: imperative, functional, and object-oriented.
- Reason about the strengths and weaknesses of the several mainstream type systems.
- Weigh the costs and benefits of static and dynamic decision making.
- Design and develop tools for recognizing and interpreting domain-specific languages.
- Develop code in languages with addressable and dynamically-allocated memory.
Share your question on Piazza, under folder midterm
.
Code
z.c
void a() {
char c = 'z';
int i = c;
}
endian.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int i = 1;
char *b0 = (char *) &i;
char *b3 = b0 + 3;
printf("Big endian: %d\n", *b3 == 1);
printf("Little endian: %d\n", *b0 == 1);
return 0;
}
printer.cpp
#include <iostream>
#include <vector>
void print(const std::vector<int>& nums) {
/* for (std::vector<int>::const_iterator i = nums.begin(); i != nums.end(); ++i) { */
for (auto i : nums) {
std::cout << "*i: " << i << std::endl;
}
}
int main(int argc, char **argv) {
std::vector<int> nums {12, 13, 18};
print(nums);
return 0;
}