Strange type conversion error in Codeblocks IDE - Page 1
Forum section: electronics / general

author: kilohercas
author_rank: Regular Contributor
timestamp: February 15, 2018, 09:24:25 pm
content: Hello, i am trying to compile simple program, but compiler gives me strange errors, and i have no work arounduint32_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 errorserror: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 ?

author: andersm
author_rank: Super Contributor
timestamp: February 15, 2018, 09:30:50 pm
content: You fubar'd the formatting (use code tags when posting code), but I'm guessing thisCode:uint32_t DLL_EXPORT CCC(uint16_t *dataIN[],uint32_t *dataOUT[])should really beCode:uint32_t DLL_EXPORT CCC(uint16_t *dataIN, uint32_t *dataOUT)orCode: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.

author: John Coloccia
author_rank: Super Contributor
timestamp: February 16, 2018, 06:03:26 am
content: 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:Code:dataOUT = dataIN;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.

author: kilohercas
author_rank: Regular Contributor
timestamp: February 16, 2018, 11:11:26 am
content: Ohh, so i just use i pointer to array and increment it, that worksNow it works

author: John Coloccia
author_rank: Super Contributor
timestamp: February 16, 2018, 12:13:14 pm
content: Quote from: kilohercas on February 16, 2018, 11:11:26 amYes, but be sure to get the function signature correct, as andersm suggested.

author: newbrain
author_rank: Super Contributor
timestamp: February 16, 2018, 02:20:20 pm
content: Quote from: kilohercas on February 16, 2018, 11:11:26 amGood 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.ais simply a shorthand for*(a+5), to the point that you can also correctly write5.See clause 20 on page 35, clause 3 on page 46, and clause 2 on page 70 ofthe draft C99 standard.