-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Replace some macros with constexpr #3362
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
Replace some macros with constexpr #3362
Conversation
src/host/_stream.h
Outdated
| _Inout_opt_ PSHORT psScrollY); | ||
|
|
||
| #define LOCAL_BUFFER_SIZE 100 | ||
| constexpr auto LOCAL_BUFFER_SIZE = 100; |
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.
This is used only in _stream.cpp. I have no idea why it's in the header file.
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.
great question. I'd be fine moving it.
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.
I just checked the history. The reason is historical artifact behind _stream.h (there wasn't a _stream.cpp in the past and it was a weird double-compiled thing for Western v. Eastern languages). I'm OK with this.
zadjii-msft
left a comment
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.
This overall looks reasonable to me. I think there's been some push to change all constants to PascalCase, (@adiviness can cite the standard I'm thinking of) but this is goodness even without doing that.
src/host/screenInfo.hpp
Outdated
| #define BOTTOM_LEFT_CORNER 4 | ||
| #define BOTTOM_RIGHT_CORNER 5 | ||
|
|
||
| static constexpr auto UPPER_LEFT_CORNER = 0; |
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.
Maybe we should file a follow-up work item to turn this into a proper enum, instead of whatever this is.
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.
(moved to #3366)
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.
The standard I was trying to apply was that macros would be SCARY_CAPS and constexprs would be PascalCase.
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.
src/host/_stream.h
Outdated
| _Inout_opt_ PSHORT psScrollY); | ||
|
|
||
| #define LOCAL_BUFFER_SIZE 100 | ||
| constexpr auto LOCAL_BUFFER_SIZE = 100; |
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.
great question. I'd be fine moving it.
src/host/screenInfo.hpp
Outdated
| #define BOTTOM_LEFT_CORNER 4 | ||
| #define BOTTOM_RIGHT_CORNER 5 | ||
|
|
||
| static constexpr auto UPPER_LEFT_CORNER = 0; |
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.
52a563d to
c8c35ca
Compare
|
Updated the PR in favor of #3371. |
| #include "terminalOutput.hpp" | ||
| #include <math.h> | ||
|
|
||
| #define XTERM_COLOR_TABLE_SIZE (256) |
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.
This is duplicate of
Line 71 in 94fc40e
| constexpr WORD XTERM_COLOR_TABLE_SIZE = 256; |
src/host/settings.hpp
Outdated
|
|
||
| // To prevent invisible windows, set a lower threshold on window alpha channel. | ||
| #define MIN_WINDOW_OPACITY 0x4D // 0x4D is approximately 30% visible/opaque (70% transparent). Valid range is 0x00-0xff. | ||
| constexpr unsigned int MIN_WINDOW_OPACITY = 0x4D; // 0x4D is approximately 30% visible/opaque (70% transparent). Valid range is 0x00-0xff. |
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.
Should this be WORD? See that's how much confusion #define caused us.
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.
And by the way do we prefer WORD over unsigned short?
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.
WORD is just a Windows-ism for unsigned short. I don't know strictly why other than Windows invented a lot of Windows-isms over the years. We've slowly been moving things to the more standard naming instead of the Windows-isms, so feel free to use unsigned short instead.
c8c35ca to
d1312b5
Compare
|
Updated the PR. For the naming part, there are too many rule-breaking Line 68 in 94fc40e
I think it's fair save the naming thing for future tasks. |
Agreed, feel free to file a follow-on issue for it. |
Summary of the Pull Request
Replace some macros with modern constexpr.
References
#2941
PR Checklist
Detailed Description of the Pull Request / Additional comments
Macros are just very 1980s and should be used less.
I'm not sure which one is preferred,
autoor concrete type.Validation Steps Performed
Not needed.