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 CCS Technical Support

Invalid type conversion?

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



Joined: 10 Sep 2003
Posts: 4

View user's profile Send private message

Invalid type conversion?
PostPosted: Mon Sep 12, 2005 9:04 am     Reply with quote

I am upgrading an existing design from a 16F877 to a 18F4525. The following code compiles and works with the 16F877 device. The compiler is PCM ver. 2.660.

My new compiler is PCH ver. 3.225. I get the error message "Invalid type conversion" at the line tmp[i] = read_eeprom(i); Does anyone have any idea why?

Many thanks,

Chris
Code:

void data_startup(void)
{
    struct data *tmp;
    int magicnuml,magicnumh;
    char magicnum[2];
    long int i;
    short rewrite = 1;

    magicnuml = read_eeprom(0);
    magicnumh = read_eeprom(1);
    magicnum[0] = magicnuml;
    magicnum[1] = magicnumh;

    if((magicnuml == 0x4A) && (magicnumh == 0x53))
    {
        rewrite = 0;
        tmp = &current_data;

        for(i = 0;i < data_size;i++)
        {
            tmp[i] = read_eeprom(i);
        }
.
.
.
Ttelmah
Guest







PostPosted: Mon Sep 12, 2005 10:26 am     Reply with quote

Post the definition of the structure 'data', and the details of what is in the variable 'data_size'.
If 'tmp', is a pointer to a structure, how can the line be valid?...

Best Wishes
cwf713



Joined: 10 Sep 2003
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 12, 2005 11:13 am     Reply with quote

Thank you for the reply. Here is the definition of the data structure.
I don't know if it is valid or not to use a pointer to store the results from read_eeprom() but it works with the old PCM compiler for some reason.

Thanks,

Chris
Code:

#define data_size 17 // the number of bytes of data contained in the struct.
struct data
{
    long magicnum;
    long up_freq;
    long down_freq;
    signed long up_gain;
    signed long down_gain;
   signed long ref_os;
    int address;
    int inputlvl;   //abs of the input level, true value always -10 - -40.
    short other;
    short mute;
    short upinv;
    short dninv;
    short remote;
    short rs485;
    short extref;
    short up_refout;
    short down_refout;
    short rs422;   
    short rs232;   
    short ref_int;   
    short ref_ext;
    short ref_auto;
    short dummy5;   //not used for anything, allows us to have an even amount of memory.
    short dummy6;   //not used for anything, allows us to have an even amount of memory.
    int chksum;     //data checksum - equal to everything in the struct except this number
                    // mod 255.
};

struct data current_data;
struct data temp_data;
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 12, 2005 11:30 am     Reply with quote

tmp should be of type char or int8 since that is the way that you are accessing it.
cwf713



Joined: 10 Sep 2003
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 12, 2005 2:45 pm     Reply with quote

I changed the type def. for the variable *ptr to int and it now compiles.
Thanks for all of the help.

Chris
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