EEVblog® Electronics Community Forum
Electronics => Microcontrollers => Topic started by: kilohercas on February 15, 2018, 09:24:25 pm
-
Hello, i am trying to compile simple program, but compiler gives me strange errors, and i have no work around
uint32_t DLL_EXPORT CCC(uint16_t *dataIN[],uint32_t *dataOUT[])
{
uint32_t i = 0;
while(i<(2400*2400))
{
dataOUT=(uint32_t)dataIN;
i++;
}
return 0;
}
It just basic memory copy to one array to another. it should work, but it is giving conversion errors
error:
invalid conversion from 'uint32_t {aka unsigned int}' to 'uint32_t* {aka unsigned int*}' [-fpermissive]|
Does any one know how to fix this ? I know i am dealing with pointers, or i just completely lost my knowledge bout pointers ?
-
You fubar'd the formatting (use code tags when posting code), but I'm guessing this
uint32_t DLL_EXPORT CCC(uint16_t *dataIN[],uint32_t *dataOUT[])should really be
uint32_t DLL_EXPORT CCC(uint16_t *dataIN, uint32_t *dataOUT)or
uint32_t DLL_EXPORT CCC(uint16_t dataIN[], uint32_t dataOUT[])That is, arrays of uint16_t/uint32_t, not arrays of pointers to uint16_t/uint32_t.
-
dataIN is a pointer to an array of uint16 pointers. dataOUT is a pointer to an array of uint32 pointer.
Most likely, you mean to say the middle thing that andersm pointed out.
The warning is exactly correct. You're casting a uint16** to a uint32, and then trying to assign it to a uint32**, and the compiler is complaining about it. You most likely mean to say:
dataOUT[i] = dataIN[i];
or
*dataOUT++ = *dataIN++;
combined with what andersm said, but it's impossible to know for sure without knowing exactly what you're passing in and what you're trying to do with it.
Personally, I despise the [] notation for arrays of unspecified size and would nearly always use pointer notation in the function signature if I can't put a fixed array size in there. Why? Because sizeof() behaves completely differently if the array is known size vs unknown size, so it's just begging for an obscure bug to creep in and bite you one of these years.
-
Ohh, so i just use i pointer to array and increment it, that works :)
Now it works :)
-
Ohh, so i just use i pointer to array and increment it, that works :)
Now it works :)
Yes, but be sure to get the function signature correct, as andersm suggested.
-
Ohh, so i just use i pointer to array and increment it, that works :)
Now it works :)
Good that it works, but I would brush up C data types again...
You are not using a "pointer to array" here (at least, I hope).
In most expression contexts, C arrays decay into pointers, specifically to a pointer to the first array element, with type pointer to element.
If a is an array, writing, e.g. a[5] is simply a shorthand for *(a+5), to the point that you can also correctly write 5[a].
See clause 20 on page 35, clause 3 on page 46, and clause 2 on page 70 of the draft C99 standard (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf).