google / styleguide

Style guides for Google-originated open-source projects
https://google.github.io/styleguide/
Apache License 2.0
37.58k stars 13.31k forks source link

header guards from different files might be the same? #78

Open dirk-thomas opened 9 years ago

dirk-thomas commented 9 years ago

cpplint uses a specific pattern for the header guards of a file. It looks to me that this pattern can lead to the same PP variable for different headers (with different names and paths).

Let me describe a simple scenario with two files:

Following cpplint rules both of them would end up using the header guard variable FOO_BAR_BAZ_H_.

Am I missing something or is this really the case? If it is, wouldn't it be better to change the rule to make these two result in different variables? E.g. a path separator could be transformed into a double underscore which would result in two different variables:

chen3feng commented 9 years ago

Then, how about: foo__bar.h foo/bar.h

dirk-thomas commented 9 years ago

There are only two options:

Since I don't see which character would be allowed in a preprocessor name which isn't in a filename I suggested a double underscore. But any sequence would be subject to a potential collision if it is allowed in a filename.