Lab 1 - Introduction to C
Due to seating limitations, you are required to go to the lab section you signed up for. If you wish to go to any other lab section, you may:
If choosing the latter option, you must email the TA in charge of your assigned lab and the TA for the lab to which you are going.
Remember that lab attendance is required; per course policy, missing 3 or more lab sections will result in a failing grade.
ssh **NETID**@sp17-cs241-**xxx**.cs.illinois.edu
You are going to need to be on campus VPN for this to work. If you want to make it work at home, make sure to log in to campus VPN then try ssh’ing. Look at the development guide!
If you added in the past 24 hours you should be getting an email soon about your VM from there you can get working. If you cannot find the assignments
You all should have gotten worksheets when you came in, these will mainly be review/expansion from the topics that you learn in lecture so shouldn’t be anything new.
Note: There is a typo in this worksheet (sorry we make mistakes too!) In a bit about bits, the line
(short | 0xCC)
-> (shifted | 0xCC)
.
Start working on the sheet, we will be around to ask some questions. We will see how long people are taking at around 15ish minutes and then go through those parts of the worksheets (the rest will be a challenge for to complete).
int a = 0;
size_t a_size = sizeof(a++);
printf("size: %zu, a: %d\n", a_size, a);
#define swap(a, b) temp = a; \
a = b; \
b = temp;
void selection_sort(int* a, size_t len){
size_t temp = len - 1;
for(size_t i = 0; i < temp; ++i){
size_t min_index = i;
for(size_t j = i+1; j < len; ++i){
if(a[j] < a[i]) min_index = j;
}
if(i != min_index)
swap(a[i], a[min_index]);
}
}
short mystery_bits(short input){
short max_set = ~0;
short masked = input & (0xFF00 ^ max_set);
short shifted = masked << 16;
short ret = (shifted | 0xCC);
return ret;
}
void positive_under_ten(int input){
if(0 < input < 10){
printf("Input is in the range\n");
}else{
printf("Input is not in the range\n");
}
}
int print_error(int err_num){
switch(err_num){
case ENOENT:
printf("No such file or entry\n");
case EINTR:
printf("Interrupted\n");
default:
break;
}
}
Given a program test arg1 arg2. valgrind --leak-check=type command
type = <no|summary|yes|full>
valgrind --show-leak-kinds=all ...
layout src
gives you a text based guibreak <file:line|function> [if condition]
You can make powerful breakpoints by giving a line, but only under certain circumstances.watch (type *)0xADDRESS
Watches an address for a read or write and tells you when it has changed – useful for when you don’t know where the bug is.backtrace
, bt
see what functions you are inup
, down
goes up and down a stack frameprint
prints a variable, (aliased p
). You can use p/x
to print in hex.next
executes the line and goes to the next line, runs functions without stopping.finish
finishes the function and breaksstep
executes the line and goes to the next line. If there is a function, gdb steps into the function.