-
Notifications
You must be signed in to change notification settings - Fork 56
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
Attempt to eliminate some MSVC /W build warnings. #28
Conversation
* Mark some functions `inline` to avoid multiple definitions error. * Change some function signatures to use `size_t` instead of `int` * Change how escape some codes are represented to avoid build warnings. * Be more explicit about casting between different `char` types. * Fixes jupyter-xeus#1
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.
Thank you for your fixes. I tested this in Ubuntu and it compiles and the Unicode still works. So I am going to merge this, and I'll send separate PRs trying to tidy that code up a bit per my comments below.
@@ -504,7 +503,7 @@ void codepoint_to_utf8(std::string &s, char32_t c) { | |||
} else { | |||
throw std::runtime_error("Invalid UTF32 codepoint."); | |||
} | |||
char u1, u2, u3, u4; | |||
char32_t u1('x'), u2('x'), u3('x'), u4('x'); |
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 think these need to be char8_t
, which should be the same as char
.
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.
It looks like 'char` is the correct type. This allows me to remove all of the static_casts. BTW - it looks like char8_t is a C++20 feature and so not available to my project yet.
@@ -513,18 +512,33 @@ void codepoint_to_utf8(std::string &s, char32_t c) { | |||
case 1: u1 = (c | mask[nbytes-1]); |
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.
In here we can type it directly to char
if it fixes the warnings.
s.push_back(static_cast<char>(u2)); | ||
s.push_back(static_cast<char>(u3)); | ||
s.push_back(static_cast<char>(u4)); | ||
break; |
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 in here we just need to take the u1
, u2
, ... and concatenate them at the end of the string s
.
I don't like this code, but I couldn't figure out how to do it better. I just got an idea, something like:
idx = s.size();
s.append(std::string(nbytes, "X"))
s[idx] = u1; idx++;
if (nbytes >= 2) { s[idx] = u2; idx++; }
if (nbytes >= 3) { s[idx] = u3; idx++; }
if (nbytes == 4) { s[idx] = u4; }
It still feels ugly, but better than the current version. I'll send a separate PR with this.
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.
changing the type of u1,u2,u3,u4 to char
allows me to remove all of these casts.
@KineticTheory I think this fixes #24, not #1, correct? |
Perfect. I also opened #33 to ensure we catch any future warnings regressions. |
Summary:
inline
to avoid multiple definitions error.size_t
instead ofint
char
types.Comments:
inline
. When I import your files into my project, I am moving many function implementations into a.cpp
file.print_rect
for me. Sorry about that style change. Have you considered using a.clang-format
file to enforce formatting choices?