This chapter mainly explains the Linux C language programming common file name, the composition of the header file, preprocessing commands, scheduled Yi Hong and other advanced use.
File suffix and file type
Header file composition (key content)
The contents of the header file consist mainly of the following sections:
1 Header File Protection (prevents a redefined error from appearing)
#ifndef ... .
#define ....
#endif ... .
2) contains other header files
#include <stdio.h>
#include <stdlib.h>
3) for macro definition
#define PI 3.1415
4 definition of structure and alias of data type
struct person
{
char name[20];
int age;
};
typedef struct person;
5 Declaration of external variables and functions
extern int num;
void show (void);
Attention:
Remember not to place the definition of a variable/function in a header file to avoid the redefinition errors that result when multiple source files contain this header file and compile the link together.
Multi-File Programming instance
Requirements: Multi-file programming to print a line of data
1 using the mkdir command to create a print directory, the VI command to write print.h print.c main.c three files are as follows:
2 Compile the connection code using the GCC command, compile the command and directory structure as follows:
The following is my personal public number, mainly as a C/s + + language technology to share the use of, Welcome to add communication: