Get the App
SLTechnology News&Howtos  ›  Network Security  › 

C language modularization development (multi-file programming)

Shulou Source: shulou.com Published: 2022-06-01 06:03:21 10月04日 Update

Up to now, most of the C language programs we have written include only one source file, and the code has not been evacuated to multiple modules, which may be accepted by Mini Program, which requires only a few hundred lines, but about large and medium-sized programs with tens of thousands of lines, it is almost a disaster to concentrate all the code in one source file, and subsequent browsing and protection will be called handy results.

In the C language, we can call a .c file a module (Module); the so-called modular development means that a program includes multiple source files (.c files) and header files (.h files).

C language code must be compiled and linked to generate executable programs:

Compilation is for a single source file (.c file). Several source files generate several destination files, and are not affected by other source files in the generation process. In other words, most of the source files are compiled independently.

The influence of the linker is to assemble these target files into an executable program and assign virtual addresses to code (functions) and data (variables, strings, etc.), which is somewhat similar to the process of building blocks.

The reason of compilation is relatively complex, involving a small number of algorithms and regular expressions, the cost of further study is high, and it is not very helpful to the development of modularization, so there is not much focus on this topic.

Learning multi-file programming, the focus is to understand the link process, that is, the linker will decompose multiple independent module groups into an executable file, in this process, there are some rules to abide by, there are some details to attract attention.

Other readers also need to understand the concept of header file, its coding standard and its introduction method.

Tags: Files source files programs modules code processes links compilations words multiple generation purpose independence programming complex similar small thematic that is that is to say Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Apple Microsoft Shulou Technology