Programming language C (XI). Preconaccumulator and library
1992/01/01 Alegria Loinaz, Iñaki | Maritxalar, Montse Iturria: Elhuyar aldizkaria
The purpose of this chapter is to explain how we can use the help provided by both compilers and ligands (called linkers) when we program it in C language.
The compilation process takes place in two phases: the first (called pre-contification) while the sentences addressed to the preconbator or the false commands are treated, the second is the translation process carried out by all compilers, obtaining the object program.
The ligand links one or more object modules (tink), resolving cross-references between them and obtaining the executable program. The modules that are associated can be user and/or standard, with the latter being the following: They are located in Library C, offer many possibilities and is one of the main sections of C capacity.
To illustrate the elements presented, we will divide this chapter into three sections: the preset, the standard library and the user libraries.
Preconaccumulator
The main possibilities offered by the preconaccumulator are three:
- Definition of parametrized constants and macros by order #define.
- Inclusion in the program of one or more source modules using #include sasiord.
- Implant conditional build fragments using #ifdef and #endif false
#define false order
By this false order the definition of constants and macros is realized as seen in chapter six. Therefore, a name is assigned a value or sequence of commands, so when you find the name, the compiler replaces and compile the corresponding value or sequence of commands. In Program 1 you can see an example:
![](images/A55025.jpg)
The meaning of the definition lasts until the end of the module if the false command #undef is not used. This new slaughter is interesting to give a new meaning to the definition, as some compilers require it before redefinition.
#include false order
By this order you can enter a source program within another, expanding the library concept to the source level.
The way to write the false order is as follows:
#include <filename> or #include "filename"
The filename defines the name of the file that you want to access and it is recommended that it be of the .h type, since this differentiates the files named header. The difference between < and > or " resides in the file location. If C is a standard title file, it will be placed between < and > for the compiler to look for in the catalog you know. The presence of " indicates that this is a user title file that will search the system in the catalog indicated by the author.
Title files are used in conjunction with libraries and distributed compilation. If some functions are compiled in a distributed module, the binder will take care of the relationship between modules, but since the parameters used in the distributed module, the data types, the definition of global variables and the type of functions are necessary in other modules, it is most convenient to include in a title file the aforementioned definitions. This file will be included in the programs used by the module functions distributed through an inclusion. An example of:
![](images/A55025-a.jpg)
#ifdef, #endif false commandments
Through these false commands it is possible to make a conditional compilation. Using this build option a sequence of commands will be included within the program if the definition is current or the compiler does not take it into account if it is not. To control the definition, in addition to commands #define and #undef, you can use the -D option of the build command (cc or msc).
This conditional option is interesting when you are developing a program for different machines and a specific machine set treatment is required.
![](images/A55025-b.jpg)
For example, if a program needs to directly handle the printer registration, you can do what is indicated in program 3 to take into account addresses of different machines.
Standard library
As explained in Chapter 6, functions must be defined before use, but there is a set of predefined functions, a set of standard functions, or, what is the same, a standard library function. We have studied some such as printf and scanf, but others not.
Table 1 shows a list of the most important functions, except for the input/output functions shown in the next chapter. Next to the functions, the name of the corresponding title file is specified, since for the use of the standard functions the corresponding title must be specified with a #include.
Program 4 includes a module that uses dynamic memory and compilation and link programs corresponding to Schema 1.
User libraries
As indicated by structured programming and software engineering, when programs are long, they must be divided into functions, forming functional sets, compiling and testing each of them separately. The modules thus created can be cataloged in a library so that the linking uses them with the referenced programs. To do this, we must take into account the characteristics of the variables analyzed in chapter 9.
![](images/A55025-c.jpg)
In this path it is very convenient to make a title file by object module or library in which constants and data types are defined, as well as functions. Schema 2 shows the compilation link schema corresponding to the program 2 seen.
In this second scheme the logic is a separate module, but has not been cataloged in a library. To do this, the ar program (with UNIX) will be used and the link command will be changed. The remaining set of commands would be:
![](images/A55025-d.jpg)
![](images/A55025-e.jpg)
![](images/A55025-f.jpg)
![](https://elia.eus/static/elhuyar/img/elia_RGB.png)
Gai honi buruzko eduki gehiago
Elhuyarrek garatutako teknologia