Week 5 Questions
1. What function does every C program have? Why should you split large programs into several functions? Functions named main (). Easy to trouble shoot problems with C program coding errors. 2. What command could you give to compile prog.c and func.c into executable named cprog?
$ cc -o cprog prog.c func.c
3. Show two ways to instruct the C preprocessor to include the header file /usr/include/math.h in you C program. Assuming that the declar.h header file is located in the subdirectory named headers of your home directory, described two ways to instruct the C preprocessor to include this header file in your C program.
#include "other.h", #include <stdio.h>, #included “math.h”, #included<math.h>, #included “declar.h”, #included <declar.h>
4. How many names of systems libraries abbreviated on the gcc command line? Where does gcc search for libraries named in this manner? Describe how to specify your own library on the gcc command line.
Libraries USE names such as libxxx.a or libxxx.so. When linked on the command line with a library, strip the lib prefix and .a or .so suffix; then prefix the remaining name with –l, as in –lxxx. By default gcc searches the /usr/lib directory for libraries. When you specify –Lpathname on the command line, gcc searches the pathname directory for each instance of –L.
Here are two command lines you could use:
$ gcc -o myprog myfile.c -L/home/mine -lyyy
$ gcc -o myprog myfile.c /home/mine/libyyy.a
5. Write a makefile that reflects the following relationships:
a. The C source files transactions.c and reports.c include a header file named accts.h
b. The header file accts.h
c. The Header file accts.h is composed of two other header files: trans.h and reps.h.
A: transactions.c and reports.c are compiled to produce an executable file named accts –ctransactions.c o transactions.o -c reports.c –o reports.o transactions.o reports.o –o my...
Please join StudyMode to read the full document