CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Unexpected "Invalid Type Conversion" Error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
UFAnders



Joined: 13 Apr 2005
Posts: 36
Location: Michigan

View user's profile Send private message Send e-mail Visit poster's website AIM Address

Unexpected "Invalid Type Conversion" Error
PostPosted: Sun Apr 30, 2006 1:28 pm     Reply with quote

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!
Ttelmah
Guest







PostPosted: Sun Apr 30, 2006 3:06 pm     Reply with quote

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
UFAnders



Joined: 13 Apr 2005
Posts: 36
Location: Michigan

View user's profile Send private message Send e-mail Visit poster's website AIM Address

PostPosted: Sun Apr 30, 2006 3:41 pm     Reply with quote

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
Ttelmah
Guest







PostPosted: Mon May 01, 2006 2:10 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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