Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: m number generator’s initial seed. 3 < 13 This is CS50. Harvard College Fall 2010 Now take a look at generate.c itself with Nano. (Remember how?) Comments atop that file explain the program’s overall functionality. But it looks like we forgot to comment the code itself. Read over the code carefully until you understand each line and then comment our code for us, replacing each TODO with a phrase that describes the purpose or functionality of the corresponding line(s) of code. Realize that a comment flanked with /* and */ can span lines whereas a comment preceded by // can only extend to the end of a line; the latter is a feature of C99 (the version of C that we’ve been using). If Problem Set 1 feels like a long time ago, you might want to read up on rand and srand again at the URLs below. Or you can execute the commands below. man rand man srand Once done commenting generate.c, re ­compile the program to be sure you didn’t break anything by re ­executing the command below. make generate If generate no longer compiles properly, take a moment to fix what you broke! Now, recall that make automates compilation of your code so that you don’t have to execute gcc manually along with a whole bunch of switches. Notice, in fact, how make just executed a pretty long command for you, per the tool’s output. However, as your programs grow in size, make won’t be able to infer from context anymore how to compile your code; you’ll need to start telling make how to compile your program, particularly when they involve multiple source (i.e., .c) files. And so we’ll start relying on “Makefiles,” configuration files that tell make exactly what to do. How did make know how to compile generate in this case? It actually used a configuration file that we wrote. Using Nano, go ahead and look at the file called Makefile that’s in the same directory as generate.c. This Makefile is essentially a list of rules that we wrote for you that tells make how to build generate from generate.c for you. The relevant lines appear below. generate: generate.c gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o generate generate.c The first line tells make that the “target” called generate should be...
View Full Document

This note was uploaded on 03/22/2013 for the course COMP SCI CS-50 taught by Professor Malan during the Spring '10 term at Harvard.

Ask a homework question - tutors are online