Skip to content
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

compiling as c++ - minor errors #42

Closed
ruby0x1 opened this issue May 31, 2024 · 1 comment
Closed

compiling as c++ - minor errors #42

ruby0x1 opened this issue May 31, 2024 · 1 comment

Comments

@ruby0x1
Copy link

ruby0x1 commented May 31, 2024

Hi, thanks for the great library!

When compiling as c++ (a misconfiguration but still potentially useful info), I found that these implicit casts are an error (via clang on mac). This may not be relevant to the code, but figured I would leave this here for posterity in case anyone needs to, or in case this is useful upstream. Feel free to close this either way.

diff --git a/runtime/io/unibreak/eastasianwidthdef.c b/runtime/io/unibreak/eastasianwidthdef.c
index 0b00d338..79c18432 100644
--- a/runtime/io/unibreak/eastasianwidthdef.c
+++ b/runtime/io/unibreak/eastasianwidthdef.c
@@ -34,7 +34,7 @@
 enum EastAsianWidthClass ub_get_char_eaw_class(utf32_t ch)
 {
     const struct EastAsianWidthProperties *result_ptr =
-        ub_bsearch(ch, eaw_prop, ARRAY_LEN(eaw_prop),
+        (struct EastAsianWidthProperties*)ub_bsearch(ch, eaw_prop, ARRAY_LEN(eaw_prop),
                    sizeof(struct EastAsianWidthProperties));
     if (result_ptr)
     {
diff --git a/runtime/io/unibreak/graphemebreak.c b/runtime/io/unibreak/graphemebreak.c
index 73622fd6..65077d54 100644
--- a/runtime/io/unibreak/graphemebreak.c
+++ b/runtime/io/unibreak/graphemebreak.c
@@ -79,7 +79,7 @@ void init_graphemebreak(void)
 static enum GraphemeBreakClass get_char_gb_class(utf32_t ch)
 {
     const struct GraphemeBreakProperties *result_ptr =
-        ub_bsearch(ch, gb_prop_default, ARRAY_LEN(gb_prop_default) - 1,
+        (struct GraphemeBreakProperties*)ub_bsearch(ch, gb_prop_default, ARRAY_LEN(gb_prop_default) - 1,
                    sizeof(struct GraphemeBreakProperties));
     if (result_ptr)
     {
@@ -98,7 +98,7 @@ static enum GraphemeBreakClass get_char_gb_class(utf32_t ch)
 static enum IndicConjunctBreakClass get_char_incb_class(utf32_t ch)
 {
     const struct IndicConjunctBreakProperties *result_ptr =
-        ub_bsearch(ch, incb_prop, ARRAY_LEN(incb_prop),
+        (struct IndicConjunctBreakProperties*)ub_bsearch(ch, incb_prop, ARRAY_LEN(incb_prop),
                    sizeof(struct IndicConjunctBreakProperties));
     if (result_ptr)
     {
diff --git a/runtime/io/unibreak/linebreak.c b/runtime/io/unibreak/linebreak.c
index c97b7b60..dc24ebc6 100644
--- a/runtime/io/unibreak/linebreak.c
+++ b/runtime/io/unibreak/linebreak.c
@@ -385,11 +385,11 @@ static enum LineBreakClass get_char_lb_class_default(
         utf32_t ch)
 {
     if (ch < 65536) {
-        return lb_prop_bmp[ch];
+        return (enum LineBreakClass)lb_prop_bmp[ch];
     }
 
     const struct LineBreakProperties *result_ptr =
-        ub_bsearch(ch, lb_prop_supplementary, lb_prop_supplementary_len - 1,
+        (struct LineBreakProperties*)ub_bsearch(ch, lb_prop_supplementary, lb_prop_supplementary_len - 1,
                    sizeof(struct LineBreakProperties));
     if (result_ptr)
     {
diff --git a/runtime/io/unibreak/wordbreak.c b/runtime/io/unibreak/wordbreak.c
index 811b15eb..e590089f 100644
--- a/runtime/io/unibreak/wordbreak.c
+++ b/runtime/io/unibreak/wordbreak.c
@@ -75,7 +75,7 @@ void init_wordbreak(void)
 static enum WordBreakClass get_char_wb_class(utf32_t ch)
 {
     const struct WordBreakProperties *result_ptr =
-        ub_bsearch(ch, wb_prop_default, ARRAY_LEN(wb_prop_default) - 1,
+        (struct WordBreakProperties*)ub_bsearch(ch, wb_prop_default, ARRAY_LEN(wb_prop_default) - 1,
                    sizeof(struct WordBreakProperties));
     if (result_ptr)
     {
@adah1972
Copy link
Owner

adah1972 commented Jun 3, 2024

Thanks for the report.

However, C follows C rules. If this project had used C++, I would have made ub_bsearch a function template. Writing a lot of casts is not good in either C or C++.

@ruby0x1 ruby0x1 closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants