amir9480 / vscode-cpp-helper

vscode extension to create implementation for c++ function prototypes.
https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.cpp-helper
MIT License
355 stars 31 forks source link

Do include guards properly #17

Closed jdlugosz closed 3 years ago

jdlugosz commented 4 years ago

When generating an include guard, don't use a name that's reserved for the implementation. Mimicing what is seen in the standard headers is a common mistake, and one reason for using an automated tool is to always get it right.

amir9480 commented 4 years ago

@jdlugosz Hello.

I need more information to understand what issue is. I'm confused now. Please describe with code samples and your suggestion about it.

jdlugosz commented 4 years ago

Names containing two consecutive underscores, or beginning with an underscore followed by a capital letter, are reserved for use by the implementation.

In short, it is exactly wrong to imitate the guards you see in the standard library files.

Your sample animation shows the example of __TEST_H__ which is a reserved name. For all you know, some standard header defines a macro by that name for its own use, or worse.

amir9480 commented 4 years ago

@jdlugosz You can change default config to remove underscores from header guards like this.

"CppHelper.HeaderGuardPattern": "{FILE}_H"

or

"CppHelper.HeaderGuardPattern": "GUARD_{FILE}_H"
alexeyr commented 4 years ago

But the default shouldn't use reserved names.