adah1972 / libunibreak

The libunibreak library
zlib License
173 stars 38 forks source link

compiling as c++ - minor errors #42

Closed ruby0x1 closed 4 months ago

ruby0x1 commented 4 months ago

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 commented 4 months ago

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++.