MISCELLANEOUS EXERCISES 1. The file badnews.c contains #include badnews.c What happens when it is compiled? 2. What does the following program do? #include int f() { int i = 3; while (i > 1) { int i = 3; printf("%d ", i--); if (i > 1) break; } return i--; } main() { int i = 3; printf("%d %d %d\n", f(), f(), f()); } 3. Replace "int" by "static int" in the first line of f in the program above. Now what does it do? (See page 83 of K and R.) 4. Suppose that a disk has 2^24 blocks, 2^12 bytes per block. All files are defined by a block with 2^6 bytes of descriptive info, followed by pointers to data blocks. How big a file can be accommodated? 5. The same disk is configured with 2^16 blocks, 2^20 bytes per block. How big a file can be accommodated? 6. Give an input string of length 10 for which the tree of Programming Assignment 7 produces a tree with all null left links. . . . ANSWERS TO MISCELLANEOUS EXERCISES 1. Puts the preprocessor in a loop. Different compilers react differently. % lcc badnews.c badnews.c:1: badnews.c: Too many open files % cc badnews.c cpp: error ./badnews.c:2: Unreasonable include nesting badnews.c:1: warning: empty input file % gcc badnews.c In file included from badnews.c:1, from badnews.c:1, from badnews.c:1, from badnews.c:1, from badnews.c:1, from badnews.c:1, from badnews.c:1, ... badnews.c:1: macro or `#include' recursion too deep 2. 3 3 3 3 3 3 3. 3 3 3 2 1 4. Pointers must be 3 bytes to accommodate 24-bit addresses. Thus, 1344 pointers ((2^12 - 2^6) / 3) can fit in the defining block, so the file size is 1344 * 2^12 = 5505024. 5. (2^20 - 2^6 / 2) * 2^20 = 1099444518912. (Use bc). 6. aaaaaaaaaa