





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Computer programs are everywhere in our daily lives. Think of Google, Facebook, Ama- zon... cellular phone, text messaging ... What are typical functionalities of a program?
The program also has to handle networking and formatting an HTML page that is shown on your browser. In fact, there are probably several programs, one for receiving your request, one for searching the database, and one for creating and formatting the output.
C was developed in early 1970s in Bell Lab for programming the UNIX operating system. At that time, OS was written primarily in Assembly. From the beginning, high perfor- mance is a major goal in C. C is one of the mostly widely used programming languages now. You can find C in high performance supercomputers as well as tiny embedded sys- tems. In fact, there are many variations of C. Some applications extend the features of C and some others restrict C. C is different from some other types of languages, especially script languages. In C, you need to declare a variable before using it. This is different from MATLAB and script programming. You have learned MATLAB in CS 159 and you will learn script programming in ECE 364.
A brief history of programming languages is available at
http://oreilly.com/news/graphics/prog lang poster.pdf.
You need three steps to execute a C program: compile , link , and execute. A compiler trans- lates a C source program (a text file we can read) to an object file (.o). Linker takes several object files and creates an executable. Finally, the program is executed. C checks types at compilation to prevent run-time type errors. We will learn more about this concept later.
Assume that you will write and rewrite (and rewrite and rewrite) the same program many times (because you will ). Do no assume that your program is perfect after you finish typing. Assume you are going to change the program many times. Make your program clear and easy to read (variable names, indentation ...)
Course Web Page:
https://engineering.purdue.edu/OOSD/S2009/S2009.html.
Introduction of the instructor and the teaching assistant.
Lectures notes will be posted on-line 24 hours before the lectures. Print the note if you want a hard copy.
Instructor’s Office Hours:
TA’s Office Hours:
Additional hours will be added later. The time may change based on the schedules of most students.
How to become a good programmer? Read and write many programs.
Email, Discussion , Submission, Scores ...
http://www.itap.purdue.edu/tlt/blackboard/.
You are strongly encouraged to interact with the instructor, the teaching assistant, and your classmates. To make communication efficient, please save time by avoiding redun-
these questions by email. Post your questions in Blackboard-Discussion. Please check Blackboard before asking any questions. Sometimes your questions have been asked and answered. Exams and assignment due dates are already posted (therefore, don’t ask). Use email for personal issues only (such as making an appointment or arranging an ear- lier exam).
Please check Blackboard regularly for announcements.
being arranged ... likely March or April
Game development. Programming PDAs. Algorithm Design. ...
convention. For example, the input arguments of main are called argc and argv. Can you change them? Yes. You can call them dog and bird and the program does exactly the same thing. C has a collection of words that are reserved for special meanings. These are called keywords (page 77 in ABOC). As long as you do not use the keywords, the com- piler does not care whether you call it argc or dog. However, you have to be careful when you violate the convention. Your program will be more difficult to read, possibly by yourself later. Rules and convention can be good. Consider this example
Everyone knows exactly what you mean when you put a note at a particular location. These are the rules. The rules make communication between musicians easier. Com- posers also follow certain convention when they write music. For example, a symphony usually has four movements. Do these rules restrict the creativity of musicians? I don’t think so. Can you say Mozart not creative? When you write a program, you have to fol- low certain rules and convention. Your creativity is built upon these rules and convention so that everyone knows exactly what you mean.
How do we compile, link, and execute the program? Let’s call the program ex1.c.
gcc -Wall ex1.c -o ex
This program has only one file so we can compile and link in one step using gcc. It is a C compiler available for many types of computers. It is open-source and free of charge. The flag -Wall means to turn on all warning messages. You should use this because warnings usually indicate errors. The file name ex1.c is provided and the output is ex1. If you do not give -o and the output name, the default output is a.out. To execute this program, simple type
./ex
here ./ means the current directory (also called folder ). This is important because it is pos- sible to have another program called ex1 somewhere else on your computer. You want to execute the program at this directory. A common error among beginning programmers is to call their program as “test”. It turns out “test” is also a program provided by UNIX. If you do not use ./test, you will call the wrong one (usually in /usr/bin/test).
If we execute the program by typing
./ex1 ece 264 spring 2009
the output is
./ex ece 264 spring 2009
The program prints the arguments one-by-one, as promised, starting from the program’s name ./ex1.
This example shows how to create a function and how to call it.
/* second.c */ #include <stdio.h> #include <stdlib.h> int add(int a, int b) { return (a + b); }
int main(int argc, char (^) * argv[]) { int val1; int val2; if (argc < 3) {