It is currently 26 May 2018 03:25

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 08 May 2018 03:30 
Offline

Joined: 08 Jan 2018 06:27
Posts: 14
Hi,
I have a compiler error "Illegal pointer conversion" issue and I can't figure out what the problem is.

I have a struct defined as below.
struct tModule {
      tByte  ModuleNo ;           // MM>>MC -
      tStr10 PartNo ;              // MM>>MC - 552nnnnnnn
      tStr10 SerialNo;             // MM>>MC - Example 180422
      tStr10 Firmware;            // MM>>MC - Example 1.23
} ;

//In my main file, I define the variable as
struct tModule MModule ;

main()

// This line generates the "Illegal pointer conversion" Error
MM_Poll_Module(1, 'D', &MModule, 10);

// This Line works correctly
MM_Poll_Module(1, 'D', &MModule.ModuleNo, 10);



When I view the code using the debugger, &MModule and &MModule.ModuleNo both have the same address ie 0x2D0A.

I want to use the address of the struct not the address of the first element within the struct.
Using the first element within the struct leaves it open to errors by somebody adding in a new variable prior to ModuleNo.

How do I get/use the address of the struct?

Thanks,
Neil.


Top
 Profile  
 
PostPosted: 11 May 2018 14:20 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9785
Hi,

Where is the definition of the MM_Poll_Module routine ?
Could you please attach the project that can be compiled which demonstrates this issue ?

Regards,
Filip.


Top
 Profile  
 
PostPosted: 12 May 2018 03:23 
Offline

Joined: 08 Jan 2018 06:27
Posts: 14
Hi,

void MM_Poll_Module(tByte ModAddr,tByte State, tAddress *DataAddr, tByte Size){

Where tByte and tAddress are defined as
typedef unsigned char tByte ;
typedef unsigned int tAddress ;

The DataAddr is later being used in a memcpy(MC_TxArray+5,DataAddr,MessSize);

The project is quite large and not something that I can make public.

Thanks,
Neil.


Top
 Profile  
 
PostPosted: 14 May 2018 15:30 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9785
Hi,

Can you please minimize your project (just the lines of code that are needed to reproduce this issue) and attach it here ?

Regards,
Filip.


Top
 Profile  
 
PostPosted: 21 May 2018 04:05 
Offline

Joined: 08 Jan 2018 06:27
Posts: 14
Can't get much simpler than this.

struct tTest {
      char  ModuleNo ;
      char PartNo ;
      char SerialNo;
};
struct tTest MTest ;

void Test(char ModAddr,char State, int *DataAddr, char Size){
}


void main() {

// This works
Test(1,'D',&MTest.ModuleNo, sizeof(MTest)) ; //

//This doesn't
Test(1,'D',&MTest, sizeof(MTest)) ; //
}


Top
 Profile  
 
PostPosted: 21 May 2018 09:25 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9785
Hi,

The parameter DataAddr is a pointer to int, while you are trying to pass a structure, i.e. the these two types are not compatible.

You can use something like this :
// casting the MTest to int
Test(1,'D',(int)&MTest, sizeof(MTest)) ; //


Regards,
Filip.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to: