Computer
Systems

Spring 2013
course
navigation

Jan 31

followup from Tues

Why Jim likes the separation of typedef and struct :
typedef struct _node *node; struct _node { node left; node right; };
This is part of a recursive data structure. Putting the definition of node first means that it can be used within the struct. (In other words, each node contains pointers to other nodes.)

chapter 1

Any questions about the overview there? Discuss these ideas:

homework

First round was generally fine.
The next one is posted. Essentially we'll spend up to two weeks to get through the end of chapter 2, spending less time on the floating point at the end.

C : pointers, bits, memory addresses

A lot of what I'm doing here (pointers) is discussed in chapter 2 of the systems text. But the C books (e.g. K&R) will also likely be helpful in mastering this stuff.
See hello alex - very cool.
Another C example: xor swap trick
/* address.c * * Output the memory addresses of some stack and heap variables. * * $ gcc address.c -o address * $ ./address * address of x is 0xbfc493ec * address of y is 0xbfc493e8 * value of zptr 0x8f3d008 */ #include <stdio.h> #include <stdlib.h> int main(){ int x; int y; int* zptr = (int*) malloc(sizeof(int)); printf(" address of x is %p \n", (void*) &x); printf(" address of y is %p \n", (void*) &y); printf(" value of zptr %p \n", (void*) zptr); return 0; }
(C errors are often less clear than (say) python. See the error that happens if you leave out include stdlib.)
On the same machine (cs.marlboro.edu)
$ free -b -t total used free shared buffers cached Mem: 3955130368 3478249472 476880896 0 603877376 2536763392 -/+ buffers/cache: 337608704 3617521664 Swap: 3305103360 0 3305103360 Total: 7260233728 3478249472 3781984256
Discuss the relations here between the amount of memory and the size & form of the pointer descriptions.
Pointers and arrays : int x[100]; // What is "x" all by itself? int* x0_ptr = &x[0]; // use some printf statements to look at these. int* x1_ptr = &x[1]; *(x0_ptr + 3) = 7; // What the heck is this doing?
If we get this far, play around with and discuss this code (from the text)
... and use this to discuss start talking about "big-endian" and "little-endian" machines. (See pg 40 - 42.)
http://cs.marlboro.edu/ courses/ spring2013/systems/ notes/ Jan_31
last modified Thursday January 31 2013 11:44 am EST