Linux under the C language advanced programming must be! (with multiple file programming code) __HTML5

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.