Skip to content

NK_STRTOD has extra const qualifier that blocks using standard library #700

@Xeverous

Description

@Xeverous

Nuklear's code:

NK_API float
nk_strtof(const char *str, const char **endptr)
{
    float float_value;
    double double_value;
    double_value = NK_STRTOD(str, endptr);
    float_value = (float)double_value;
    return float_value;
}

The problem - standard library is incompatible:

// C89
double strtod(const char *restrict str, char **restrict str_end);
// C++ (any version)
double strtod(const char* str, char** str_end);

If I #define NK_STRTOD strtod then I'm getting the following error:

[...]/Nuklear/nuklear.h: In function ‘float nk_strtof(const char*, const char**)’:
[...]/Nuklear/nuklear.h:6841:35: error: invalid conversion from ‘const char**’ to ‘char**’ [-fpermissive]
 6841 |     double_value = NK_STRTOD(str, endptr);
      |                                   ^~~~~~
      |                                   |
      |                                   const char**
/usr/include/stdlib.h:118:27: note:   initializing argument 2 of ‘double strtod(const char*, char**)’
  118 |         char **__restrict __endptr)
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~

Can you change the implementation so that it supports the standard library (without const)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions