![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
UFAnders
Joined: 13 Apr 2005 Posts: 36 Location: Michigan
|
Unexpected "Invalid Type Conversion" Error |
Posted: Sun Apr 30, 2006 1:28 pm |
|
|
Gentlemen-->
I am getting an unexpected type conversion error in my program where I pass two structures into a function as pointers...
Structure definitions:
Code: | static struct columnMAX7313
{
int8 pixel[8]; //8 bytes store brightness data for 16 pixels!
} columnRealTimeMAX7313; |
Code: | static struct frameMAX7313
{
struct columnMAX7313 columns[64];
} frameRealTimeMAX7313; |
Function prototype:
Code: | void transformFrame2(unsigned char methodFrame, struct columnMAX7313 *this_column, struct frameMAX7313 *this_frame); |
Function Definition:
Code: | void transformFrame2(unsigned char methodFrame, struct columnMAX7313 *this_column, struct frameMAX7313 *this_frame)
{
signed int16 cycle=0;
struct columnMAX7313 tempColumn2;
switch(methodFrame)
{
case shiftRight:
for(cycle=63; cycle>(-1); cycle--)
{
if(cycle!=0)
{
tempColumn2 = this_frame->columns[cycle-1];
this_frame->columns[cycle] = tempColumn2;
}
else
{
this_frame->columns[cycle] = this_column;
}
}
break;
case shiftLeft:
for(cycle=0; cycle<64; cycle++)
{
if(cycle!=63)
{
tempColumn2 = this_frame->columns[cycle+1];
this_frame->columns[cycle] = tempColumn2;
}
else
{
this_frame->columns[cycle] = this_column;
}
}
break;
default:
break;
}
} |
I call the function like so: Code: | transformFrame2(shiftLeft, &columnRealTimeMAX7313, &frameRealTimeMAX7313); |
The area that gives me the error is the "this_frame->columns[cycle] = this_column;" line present in both shift directions. The compiler says "Invalid Type Conversion." However, if I use "this_frame->columns[cycle] = *this_column;" I get an ok compile, but the function doesn't seem to work.
I am using PCH 3.217. Any ideas?
Endless thanks! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Apr 30, 2006 3:06 pm |
|
|
The line:
"this_frame->columns[cycle] = this_column;"
is invalid.
If you think about it, "this_frame->columns[cycle]", is a structure of type columnMAX7313, while "this_column", is a _pointer_ to such a structure. Not suprising you get a complaint.
Second comment, don't use '&columnRealTimeMAX7313', or the other '&' reference. A structure name, just as for an array, _is_ the address of the data, so you are taking the address of the address, and handing this to the routine, which then treats this as the address of the structure. Either just use the structure name, or pass the address of the first element in the structure.
Final comment. How well the compiler handles moving structures as single elements, depends on how recent it is. In the past there were problems, and you may well find it 'safer', to use a memcy, with the size of the structure, to be sure.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
UFAnders
Joined: 13 Apr 2005 Posts: 36 Location: Michigan
|
|
Posted: Sun Apr 30, 2006 3:41 pm |
|
|
Kind Sirs-->
I left the prototypes alone, but I removed the ampersands from the function call for transformFrame2([...]) and changed
Code: | this_frame->columns[cycle] = this_column; | to
Code: | this_frame->columns[cycle] = *this_column; | .
Now the compiler tells me that "A numeric expression must appear here" at the function calls.
Would anyone be able to inform me of my surely inane mistakes? ![Laughing](images/smiles/icon_lol.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon May 01, 2006 2:10 am |
|
|
Do what I said, and pass the address of the first element.
Also, I would suggest using memcpy, rather than just passing the structure. The compiler is slightly 'laboured' in handling structures at times, and while the recent versions do seem now to handle passing a whole structure between variables, it is a 'recent enough' feature, that I still feel 'happier' going manual.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|