You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What syntax I should use in the second case? Also, how the json deals with the array size, as in this case the array is not \0 terminated. (contains binary data).
Thanks for help.
The text was updated successfully, but these errors were encountered:
unsigned char iv[2] is seen behind the scene as pointer to allocated memory and as you rightly wrote has no information about the size.
There are several possibilities to achieve what you want to do but the best solution depends on your real problem. If iv has always 2 elements just use each of them directly.
Otherwise make it the argument a const std::vector<unsigned char> &. Then JSON will be able to convert it directly to an array (because std::vector contains the number of elements).
Please elaborate with more details to get a better answer.
Passing C-style arrays as arguments to functions doesn't really work well (due to legacy C rules that require that arrays decay to pointers, so you're actually dealing with "MyF(unsigned char *iv)" which has no size information and doesn't even look like an "array").
As @pboettch says, you could pass it in as a std::vector. You could also use a std::array. As a last resort -- an ugly solution that I would not recommend -- you can pass the array by C++ reference, and then you'll also get what you expect (I'm not telling the syntax for this because it's awful and ugly and I really recommend doing it another way :)
Thanks for the response!
The reason why I have it this way is that the array has a const number of element, so it is always well known parameter. Also it has no overhead like other more complex types, like a Vector. I found out a worked solution like this:
for (int i = 0; i < IV_LENGTH; i++) { items["IV_ValueHex"].push_back(iv[i]); }
or for (int i = 0; i < IV_LENGTH; i++) { items["IV_ValueHex"][i] = iv[i]; }
Hi,
I can create an array field with the following syntax, used inside a finction:
However, if I pass iv as a function argument, than the code doesn't compile:
I get an error 'No match for operator ='
What syntax I should use in the second case? Also, how the json deals with the array size, as in this case the array is not \0 terminated. (contains binary data).
Thanks for help.
The text was updated successfully, but these errors were encountered: