nixawk / hello-c

c programming
9 stars 11 forks source link

c - PROGRAM ORGANIZATION #14

Open nixawk opened 7 years ago

nixawk commented 7 years ago
screen shot 2017-10-17 at 21 36 58

Program Files

A C program consists of one or more program files, one of which contains the main( ) function, which acts as the driver of the program. When your program is large enough to require several files, you should use encapsulation and data hiding techniques to group logically related functions and data structures into the same files. Organize your programs as follows:

README File

A README file should be used to explain what the program does and how it is organized and to document issues for the program as a whole. For example, a README file might include

Standard Libraries

A standard library is a collection of commonly used functions combined into one file. Examples of function libraries include “stdio.h” which comprises a group of input/output functions and “math.h” which consists of mathematical functions. When using library files, include only those libraries that contain functions that your program needs. You may create your own libraries of routines and group them in header files.

Header Files

Header files are used to encapsulate logically related ideas; for example the header file “time.h” defines two constants, three types, and three structures, and declares seven functions needed to process time. Header files may be selectively included in your program files to limit visibility to only those functions that need them.

Header files are included in C source files before compilation. Some, such as “stdio.h” are defined system-wide, and must be included by any C program that uses the standard input/output library. Others are used within a single program or suite of programs.

Module Files

A module file contains the logically related functions, constants, types, data definitions and declarations, and functions. Modules are similar to a program file except that they don’t contain the main( ) function.

Makefiles

Makefiles are used on some systems to provide a mechanism for efficiently recompiling C code. With makefiles, the make utility recompiles files that have been changed since the last compilation. Makefiles also allow the recompilation commands to be stored, so that potentially long cc commands can be greatly abbreviated. The makefile

Standard Filename Suffixes

The suggested format for source code filenames is an optional prefix (e.g., to indicate the subsystem), a base name, and an optional period and suffix. The base name should be unique (length may vary depending on your compiler; some limit filenames to eight or fewer characters) and should include a standard suffix that indicates the file type. Some compilers and tools require certain suffix conventions for filenames. Figure 3 lists some standard suffixes; or use those dictated by your compiler.

screen shot 2017-10-17 at 21 47 59