☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

避免在 include 指令中使用绝对路径

3.1.4 ID_forbidAbsPathInHeaderName
目录 › next › previous

如果 include 指令中的头文件路径为绝对路径,会使项目依赖特定的编译环境,降低可移植性。

示例:

#include "C:\\foo\\bar.h"   // Non-compliant
#include "/foo/bar.h"       // Non-compliant

应使用相对路径或由构建工具定义的路径:

#include "../bar.h"   // Compliant, a relative path
#include BAR_H_PATH   // Compliant, a macro defined by building tools
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.