C/C++头部保护一致性

use*_*947 2 c c++

我需要一个实用程序来检查标题保护中的冲突.如果实用程序可以检查符号和文件名是否一致(使用正则表达式或其他东西),那将是很好的.

问候,rn141.

编辑:

示例1.断头防护罩.不能防止多重包含.

// my_file1.h
#ifndef my_project_my_file1_h__
#define my_project_my_fil1_h__ // should be my_project_my_file1_h__
    // code goes here
#endif
Run Code Online (Sandbox Code Playgroud)

示例2.与上述标题保护冲突.

// my_file2.h
#ifndef my_project_my_file1_h__ // should be my_project_my_file2_h__
#define my_project_my_file1_h__ // should be my_project_my_file2_h__
    // code goes here
#endif
Run Code Online (Sandbox Code Playgroud)

Ash*_*ain 5

怎么用#pragma once呢?

  • 并非所有编译器都支持`#pragma once` (5认同)