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

Pointer warning....
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 10, 2016 2:58 pm     Reply with quote

jeremiah wrote:

For me it depends on if I use copy/paste from PCM's example or if I
further cast the pointer going into write_eeprom call

I think you're right. I was concentrating on solving his problem of a
parameter type mis-match error. I ignored the contents of his
EEProm_Put() function.
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Wed May 11, 2016 12:51 am     Reply with quote

Problem is that as PCM_Programmer is doing it, by using the structure type into the call, the pointer is cast every time in the actual write loop.

I didn't use this approach, since it will then give the problem again, if you use a different sized variable for the put function. Whole point is that you want the function to be able to handle any size 'source'.

Casting externally in the call, only does the cast once, and it'll then work for every type used. Done like this, for me, the size only grows for one copy operation, and the code for EEPROM_put does not change.

Honestly the best way to me, seems to be to just disable the warning. Do it explicitly for the one call only if required.

The problem actually is that CCS does not have the concept of a 'void' pointer (CCS's 'void *', is actually an int8 *, and does not alter the error behaviour)
Adding the warning without this, leads to it being a pain to avoid.

With a proper 'void' pointer, the language should then accept that this does not have a size associated. You would then define the function to cast this to the size required internally. This should be pointed out to CCS (all it needs is for them to alter the warning code, so if one or both of the pointers are 'void *', the warning is not triggered).

In fact though, using the void * approach, does give a working/elegant way of making it function:
Code:

#include <18f26k22.h>
#use delay(crystal=10MHz)
//Only demo prog, not for a PIC.

struct
{
 int16 x;
 int8 y;
 char c;
 char s[20];
} EEData;

#define EEPosData1 (void *)&EEData,sizeof(EEData),10+1

void EEProm_Put(void * ptr, int8 size, int8 addr)
{
 int8 count;
 for (count=0;count<size;count++) { WRITE_EEPROM(addr+count,((int8 *)ptr)[count]); }
}

void main(void)
{
 EEProm_Put(EEPosData1);
}   


This avoids the code expansion in the EEPROM_put call, gets rid of the warning, and compiles to just 132 bytes.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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