문제

Im trying to enter a double value in the same hdf5 databse. It consist (for now) of 1 dataset which I extend before entering a new value. That is because I am simulating a model and want to record > 100000 entries. That works well, the extending part too, but I do not understand a part of the writing. My code for writing an entry:

double pizza[1] = {7.0};
status = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace,H5P_DEFAULT, pizza);

With dataset, memspace, and filespace correct variables for the corresponding argument (taken from here). But why should the last argument be a predefined list? When I try to enter 7.0 directly

    status = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace,H5P_DEFAULT, {7.0});

like this or this:

    status = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace,H5P_DEFAULT, 7.0);

it gives an error:

    error: cannot convert ‘double’ to ‘const void*’ for argument ‘’ to ‘herr_t H5Dwrite(hid_t, hid_t, hid_t, hid_t, hid_t, const void*)’ = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace,H5P_DEFAULT, 7.0);

And in the second case:

    error: cannot convert ‘<brace-enclosed initializer list>’ to ‘const void*’ for argument ‘6’ to ‘herr_t H5Dwrite(hid_t, hid_t, hid_t, hid_t, hid_t, const void*)’H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memspace, filespace,H5P_DEFAULT, {7.0});

Why is a list different then a single value, even when surrounded by brackets?

도움이 되었습니까?

해결책

compiler is taking the value 7.0 and by default its the nature of the compiler to convert it into double. Hence it is showing you this error.

If you need to make it work, use the base address of pizza , and type cast it into (const void *)

The brace enclosed initializer list might be coming because compiler thinks its a variable arguments list.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top