Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Wed May 11, 2016 12:51 am |
|
|
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. |
|