C language prevents header files from being referenced multiple times

write code snippet here

comm.h and comm.c are common modules.
test1.h and test1.c use common modules.
test2.h and test2.c use common modules.
test.h and test.c use the test1 module and test2 module.
In this way, there will be two copies of comm.h in the final program. This results in duplication of file content.

1. Method 1

It's ok to add this sentence at the beginning of the file

#pragma once

2. Method 2

Put header files in "header files"

ifndef __TEST_H__
#define __TEST_H__
//头文件
#endif //__TEST_H__

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325685197&siteId=291194637