Piccolo icon indicating copy to clipboard operation
Piccolo copied to clipboard

Replace "#pragma once" macro with header guard

Open wlbksy opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe.

google c++ code style header guard is preferred than "#pragma once"

Describe the solution you'd like

replace those "#pragma once" with header guard

wlbksy avatar Apr 18 '22 02:04 wlbksy

I think it's not necessary to replace #pragma once with header guard. #pragma once has been well supported across compilers since not actually part of the standard, and it's less prone to make mistakes and less code to type.

hyv1001 avatar Apr 21 '22 02:04 hyv1001

I actually think compiler dependent is part of the problem, although it's not so urgent.

In fact, you don't even have to type in these guards. Lots of IDEs, even editors such as "vs code" would do these things automatically.

If we were to do this, we could also enforce cpplint and clang-format in the CI procedure.

wlbksy avatar Apr 21 '22 05:04 wlbksy

使用头文件保护会导致以后修改文件名的时也需要一起修改宏的名称, 而使用 #pragma once 则没有这个顾虑. 在编译器兼容性方面, #pragma once 应该不再是一个问题了, 如果代码检查工具依然存在相关的规则, 可以考虑将相关规则禁用.

ShenMian avatar May 23 '22 07:05 ShenMian