Hi all, Before Q&A, here are general guidelines for this course. 1. This course assumes you take at least one programming course. Most of you did take the Java programming course, so I assume you are familiar with basic program structures. That said, if you are not familiar with any programming language, pay special attention to precepts where TAs teach mechanical parts of C programming, and carefully read the books according to the schedule in the syllabus. The lectures will mainly talk about high-level concepts (design, testing, debugging, style, etc.) while precepts deal with the low-level stuff. 2. Read the books. Lectures and precepts will be limited in terms of coverage, and you need to fill the gap on your own to some extent. Especially, if you didn't take the Java programming course, you may be confused with "expressions, statements, functions, directives, etc.". Precepts will eventually catch up with the schedule, but for the first few weeks, you need to read the books ahead to grasp the concepts to be able to follow the lecture materials and to do the programming assignments. 3. Ask questions. Bring a blank sheet with you each class, and write down your questions and turn it in. Use this mailing list to ask any questions (that are not "on your own" part) on assignments, lecture materials, and C programming in general. Don't be shy. --------------------------------------------------------------------- 1. What is "stderr" in fprintf(stderr, "...")? => That is the file pointer to standard error stream. defines three file pointers for standard streams (stdin, stdout, stderr) which you can use in file manipulation library functions (that typically start with fblah() such as fread, fwrite, feof, fstat, etc.). That is, you can apply these file input/output (I/O) functions to the standard streams just like you're dealing with a file (we'll learn file manipulation later.) For now, whenever you want to write to stderr stream, it's safe to remember to use fprintf(stderr, "..."). It's the same as printf except that it can write to any file or stream. In contrast, printf only writes to standard output stream. You may wonder why we need standard error stream. This could be useful when you have to separate the valid output and error/warning messages. The default standard error is the display (the same as stdout), but you can redirect each stream to two different files, such as. ./sampledecomment < file1 >output 2>error Note that "2" in "2>" specifies the standard error stream for redirection. 2. I'm not good at English listening, could you please slow down? => Sure. I'll definitely try slowing down. It's not always easy though since I tend to forget it, but let me know in the class if I'm too fast. 3. What's the case or example that unsigned type can be used? => Anywhere you absolutely don't need a negative value. If you have to represent a negative value even in the remote future, it's good to use a signed type. 4. I can use "//" as a one line comment in C, in addition to /* .. */ even in visual studio 6.0, which was released before C99 was released. How is this possible? Should I always use type /*...*/ for the programming assignments? => Implementation of some language features are added before they are standardized. // has been widely used in C++ even before C99, so it's not surprising many preprocessors (predating C99) support the feature. About the programming assignments, feel free to use any language features that are supported by our lab machines. That is, you need to check if a certain (non-standard) feature is supported by our gcc on lab machines. 5. What's the range of values that Ones' complement can represent with n bits? => For an n-bit integer in ones' complement form, we can represent -2^(n-1)+1 ...-0, +0, ..., 2^(n-1) - 1. That is, you have 2^(n-1) -1 positive and negative values each and two zeros that you can represent in ones' complement form. 6. Slide 15, how come did you get -5536 (= 10000 + 20000 + 3000). => With 16 bits in two's complement form, the maximum positive value is 2^15-1 = 32767. 10000, 20000, 30000, by itself is in the valid range, but if you add them all, we get 60000, which is beyond the positve value range that 16-bit two's complement form can represent. 60000 is 0xEA60 in hexadecimal, and since the most significant bit (MSB) is 1 (E = 1110 in binary), it is a negative value in two's complement form. Two's complement of 0xEA60 is ~(0xEA60) + 1 = 0x159F + 1 = 0x15A0 = 5536. That is, 0xEA60 is -5536. 7. In for (...; ...; n >>= 1), why not just use 'n >> 1' instead of n>>=1? => n >> 1 shifts all bits to the right by one bit, but it does not update the value of n. What you want is to update n with the value of (n >> 1). n = (n >> 1) is what you want (assignment), and n >>= 1 is abbreviation of the assignment with the right shift operation (called compound assignment). Refer to Chapter 4.2 in King's book. 8. What is Unix? => Unix is an operating system like MS Windows. An operating system boots up the computer and allows you to run applications on top of it. Also, it manages various hardware resources and abstract them and provide easy and intuitive interface to the applications. For example, in order to write to a file on a disk, all you need is to call library functions (like fwrite(), fprintf()) and provide the data to be written instead of figuring out disk-specific details (disk/sector/track/spindle #s for the address). 9. In scanf("%u", &n), why don't we use "%d" instead of "%u"? => %u is for unsigned integers where "%d" is for signed integers. n is defined to be unsigned, "%u" is better to be used than "%d". 10. What is fprintf()? => It's the same as printf() except that you can also specify the file pointer as the destination. See the above. --KyoungSoo Assignment #1: As you know, the first assignment is due this Sunday. If you don't have any clue at all, please start with the source code we studied in the second lecture (the example that capitalizes the first letter of each word). Define a DFA that solves the problem, and convert the DFA to a C program. Use getchar() to read one character at a time from stdin, and in case of an error, use fprintf(stderr, "..."). From the perspective of a program, all input is coming from stdin, so you don't need to worry about redirection. Redirection is done by the user of your program. --KyoungSoo