-
Notifications
You must be signed in to change notification settings - Fork 65
[ML] Correct the way internal linkage of constants is achieved #102
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
[ML] Correct the way internal linkage of constants is achieved #102
Conversation
1. There's no need for constants declared in unnamed namespaces to be declared static - they already have internal linkage 2. Constants of type char* pointing to literals should be declared const char* const - declaring them const char* does not result in internal linkage because it allows them to be changed to point at something completely different!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. left a question
#else | ||
#ifdef __GNUC__ | ||
// Tell g++ that it's reasonable that this variable isn't used | ||
__attribute__((unused)) static const char* LINE_ENDING = "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, now this really is a constant with internal linkage it's not needed.
In fact, the warning from g++ was the canary in the mine warning that something was not right. Suppressing the warning was the wrong way to avoid it.
1. There's no need for constants declared in unnamed namespaces to be declared static - they already have internal linkage. 2. Constants of type char* pointing to literals should be declared const char* const - declaring them const char* does not result in internal linkage because it allows them to be changed to point at something completely different!
Follow-on to elastic#102. Fixing more places where pointers intended to be immutable could be changed to a point at a different constant.
Follow-on to #102. Fixing more places where pointers intended to be immutable could be changed to a point at a different constant.
Follow-on to elastic#102. Fixing more places where pointers intended to be immutable could be changed to a point at a different constant. Backport of elastic#409
to be declared
static
- they already have internal linkage.char*
pointing to literals should bedeclared
const char* const
- declaring themconst char*
doesnot result in internal linkage because it allows them to be
changed to point at something completely different!