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

json_printf_array with "%f" does not work #52

Open
jkent opened this issue Jun 14, 2019 · 0 comments
Open

json_printf_array with "%f" does not work #52

jkent opened this issue Jun 14, 2019 · 0 comments

Comments

@jkent
Copy link

jkent commented Jun 14, 2019

Example code:

void test_case(float arr[], size_t len)
{
    for (int i = 0; i < len; i++) {
        printf("%f\n", arr[i]);
    }

    char *json = json_asprintf("{state:{reported:{temps:%M}}}",
                               json_printf_array, arr, len * sizeof(arr[0]),
                               sizeof(arr[0]), "%f");
    if (json) {
        printf("%s\n", json);
        free(json);
    }
}

int main(int argc, char *argv[])
{
    float arr[3] = {
        1.1,
        2.2,
        3.3
    }; 

    test_case(arr, 3);

    return 0;
}

The printf of the loop is correct. The correct number of elements are added to the json, but they are all zero. This is being compiled for the esp32 with xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a) 5.2.0

I've copied the elements to an array of double using "%lf" and this is a workaround for the problem.

Edit: Added a main and tested on amd64 as well, and repro'd there too. I was worried this might be due to the esp32 hardware float lazy context switch.

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

1 participant