Author Topic: Strange type conversion error in Codeblocks IDE  (Read 1238 times)

0 Members and 1 Guest are viewing this topic.

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Strange type conversion error in Codeblocks IDE
« 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 ?

 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Strange type conversion error in Codeblocks IDE
« Reply #1 on: February 15, 2018, 09:30:50 pm »
You fubar'd the formatting (use code tags when posting code), but I'm guessing this
Code: [Select]
uint32_t DLL_EXPORT CCC(uint16_t *dataIN[],uint32_t *dataOUT[])should really be
Code: [Select]
uint32_t DLL_EXPORT CCC(uint16_t *dataIN, uint32_t *dataOUT)or
Code: [Select]
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.

Offline John Coloccia

  • Super Contributor
  • ***
  • Posts: 1212
  • Country: us
Re: Strange type conversion error in Codeblocks IDE
« Reply #2 on: February 16, 2018, 06:03:26 am »
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: [Select]
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.


« Last Edit: February 16, 2018, 12:11:56 pm by John Coloccia »
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: Strange type conversion error in Codeblocks IDE
« Reply #3 on: February 16, 2018, 11:11:26 am »
Ohh, so i just use i pointer to array and increment it, that works :)
Now it works :)
 

Offline John Coloccia

  • Super Contributor
  • ***
  • Posts: 1212
  • Country: us
Re: Strange type conversion error in Codeblocks IDE
« Reply #4 on: February 16, 2018, 12:13:14 pm »
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.
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Strange type conversion error in Codeblocks IDE
« Reply #5 on: February 16, 2018, 02:20:20 pm »
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.
« Last Edit: February 16, 2018, 02:29:07 pm by newbrain »
Nandemo wa shiranai wa yo, shitteru koto dake.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf