<> introduction

*
In a complex program ,c All the data types of language can not meet our needs , Often need to define their own data structure . There will be a problem here , When your code is not stored in a source file , And there is also the transmission of structure data between functions . So how to share the same structure in different source files ?
<> Different source files share the same structure

*
first , We may consider defining the same structure in different source files , however , Although the data types of structures are the same , The name is the same , But in the compiler compilation process , It's not the same data type , And report a mistake ( The data type you passed in does not match what you need ).
* Whether it's an integrated environment or gcc Compiler, his method is the same .
* First define a header file // Header file str.h #ifndef _STR_H_ //ifndef namely if no define The abbreviation is
// If there is no definition, execute the following code , definition // There's no need to redefine it ._STR_H_ This is yours // The header file name is capitalized and underlined . #define _STR_H_
typedef struct { char *ch; int length; } Str; #endif
2. This header file is introduced into each source file
#include "str.h"

* Because there is a judgment in the header file first , You don't have to worry about multiple structs generated at compile time .

Technology