-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What a bout adding : Avoid macro name collision by prefixing all the macros with a prefix #227
Comments
A good point about macro naming rules in general. However, the focus on the implementation detail of |
I believe the issue with If we want these global symbols, we need them as keywords of the C++ standard (as e.g. static_cast) and the user could not use them. This will of course be a breaking change and need enough attention. Does the C++ Core guidelines want to add specific keywords to the c++ language? I' would add a rule: "Libraries must not add global symbols" . If absolutely needed they must follow the C prefix mylib_ or MYLIB_ idiom, to avoid possible clashes with other libraries and applications. I agree that prefixing is not nice, but at least it doesn't break user code. A library (in particular GSL) could provide these user only global functions in a specific file (with a BIG comment) as far as it doesn't use them at all. It is the responsibility of the final user to include these files. If the C++ Core guidelines are for C++17/20 and we know already that |
We don't know at this point what WG21 will decide. An attribute syntax was suggested; others want keywords. I suspect the particular emphasis on Anyway, regarding symbols: what is the practical difference between a keyword, an operator (which effectively is a global symbol), or an alphabetic function (e.g. swap) that happens to be effectively an operator spelled differently? Also note that GSL isn't just any ordinary library. GSL assumes C++14. Regarding "breaking user code", we are interested and attentive to actual user codes that are broken. Maybe this issue is conflating too many things in one? |
What about a guideline about naming include-sentinels in header files? Many files use double underscored names for defines, some often use just header name like #ifndef SI__DIR1__DIR2__FILENAME_H__INCLUDED Or do you think that such guildeline belong to a code-style book of a project? |
@mcvsama, there is a better way to control preprocessor inclusions:
|
@os12 Is it part of a standard? |
I am not sure whether this has been standardized. It works in VC++/GCC/Clang... |
http://stackoverflow.com/a/23699893 says it's not standarized because of problems with reliability. What a pity. Thanks for sharing that, anyway. |
#pragma once isn't standard, even if implemented by popular compilers. |
Editors discussed on 11/16/2015. |
Macros a global and don't have scope, so the C naming rules should apply.
I would add a rule, avoid macro name collision by prefixing all the macros with a prefix MYLIB_, MYAPP_.
This is in conflict with Expected and Ensures.
The text was updated successfully, but these errors were encountered: