Preprocessing and construction data

Source: Internet
Author: User


Knowledge can grow with given

First, pre-processing (precompiled)
Definition: Processing of a program prior to compilation
Precompiled compile-assembly link
*.c--> *.i-> *. S-> *.o-> Elf
MOV R1, r2-> 1010 0001 0010

Include: Header file contains, macro definition, conditional compilation

Second, the header file contains
Role: The content of a lot of compilation unit is stored in a file, who uses who contains the file, avoid a lot of repeated writing.
Mainly includes: function declaration, macro definition, struct-body definition
Processing mode: Fully expanded, if the header file contains other header files,
will be expanded recursively
#include <xx.h>:
Go to system default directory lookup
#include "xx.h":
First in the current directory to find, can not find the system default directory lookup

Header files cannot be included repeatedly, resulting in duplicate definitions;
However, you can avoid this problem by using the following methods.

#ifndef _stdio_h_
#define _stdio_h_

#endif/* _stdio_h_ */

Three, macro definition
Definition: A simple and easy-to-remember name represents a specific content
Example: #define PI 3.14159
How to: Simply replace
Advantages: Enhanced readability of code, simple writing

With parameter macro: not equivalent to a function
1, if the entire equation has a return value, you need to add parentheses
2, the parameters to participate in the operation need to add parentheses

Iv. conditional Compilation
Definition: Specifying a compilation condition for a piece of code
Process: Participate in or not participate in compilation
Format one:
#if an expression

#endif

#ifdef macro

#endif

#ifndef macro

#endif

Format two:
#if an expression

#else

#endif

Note: There is no explicit document provision, generally according to the function module

Five, structural body
Definition: A structure that combines variables of multiple data types
Keyword: struct
Format:
typedef struct BOOK {
Char name[20];
Char author[200];
float price;
}book;
Variable definition: Book Book1;
Member variables:
Variable name. Member Name
Pointer name, member name
A struct can be assigned as a whole, and when passed as a function parameter, the value is passed
Size: Each member has its own storage space, but it is not simply added, but also related to the storage alignment of the data.
struct definition: Can contain other types of struct variables, but cannot contain its own structure variables;
Can contain pointer variables that point to its own type

Vi. Consortium
Definition: Multiple variables occupy the same memory space structure, called the common body
Keyword: union
Characteristics:
1, size equals the size of the largest member of the storage space
2. Only one member is valid at a time

Vii. Enumeration
Definition: Enumerate the possible values of variables,
The value of a variable can only be evaluated within the range enumerated.
Some people also refer to enumerations as collections of a bunch of macros
Keyword: enum
Features: The enumeration value defaults to a sequential integer starting from 0, incrementing sequentially;
You can specify an enumeration value when declaring an enumeration type.
The specified enumeration values are incremented sequentially.
Advantages: Improved readability of code

The visible constants in the program are called Magic Numbers and should be used sparingly.

Practice:
1, write a simple dictionary, to achieve the search function, dictionary of words and definitions stored in a character pointer array, format:
Char *dic[] = {
"Apple:??",
"Banana:??",
};
Requirements: The declaration is placed in the header file, the implementation is placed in a different C file, where the string operation is placed in the strop.c, the sorting function is placed in the sort.c, the two files have their own header files.
2. Set one of the data (0/1-> 1)
3. Clear one of the data (0/1-> 0)
4, take the anti-one of the data (0–>1, 1–>0)
5. Print a binary version of a number, such as: 250, Print: 11111010
A & (1<<i) ==0 A for the first place is 0





Preprocessing and construction data

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.