View previous topic :: View next topic |
Author |
Message |
raman00084@gmail.com
Joined: 28 Jul 2014 Posts: 38
|
warning message |
Posted: Tue Jul 04, 2023 3:07 am |
|
|
Dear sir,
I have installed the demo version pcwhd (45 days) on my pc.
I compiled a project that was running in PCD compiler v5.045, i am getting a
warning message pointer type do not match. In PCD compiler v5.045 i am not getting this warning.
Code: |
void split_32_to_8(int32 val,char*data)
{
unsigned int8 *val_ptr = (unsigned int8 *)&val;
for(int a = 0; a < 4; a++)
{
data[a]=*(val_ptr + a);
}
}
unsigned int8 data_4[5]={'\0'};/// local array
split_32_to_8(value,data_4);
|
I am getting warning message pointer type does not match on
split_32_to_8(value,data_4);
The error line comes in the above data_4. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9222 Location: Greensville,Ontario
|
|
Posted: Tue Jul 04, 2023 5:12 am |
|
|
If you're wanting to split a 32 bit word into 4, 8 bit bytes... it'd be better to use 'UNION".
It's fast,small and works. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Tue Jul 04, 2023 11:38 pm |
|
|
and the union also avoids possible pointer type problems.
Or just use the compiler's 'make8' function.
You have to be _very_ careful of pointers on the 16bit chips. Understand
that pointers on these can point to int32 int16 or int8 values, and mixing
these can cause address error traps, since (for example), it is illegal
to access an int16 value, with an odd pointer.
In your posted code, you don't show how 'value' is declared. However
the warning, is because 'data_4' is declared as unsigned int8, while the
split function declares the array as char. By default char is a signed int8.
Better honestly, if you are using these as byte values to declare both as
byte. Using the union though saves hundreds of bytes of code. |
|
|
raman00084@gmail.com
Joined: 28 Jul 2014 Posts: 38
|
|
Posted: Wed Jul 05, 2023 4:04 am |
|
|
i am passing unsigned int8 to char.
the problem solved |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Wed Jul 05, 2023 6:15 am |
|
|
It is important to realise just how inefficient this is:
Code: |
void split_32_to_8(int32 val,byte*data)
{
byte *val_ptr = (byte *)&val;
for(int a = 0; a < 4; a++)
{
data[a]=*(val_ptr + a);
}
}
void main()
{
int32 value=12345;
byte data_4[5]={'\0'};/// local array
split_32_to_8(value, data_4);
//Versus
union {
int32 value;
byte data_4[4];
} splitter = 12345;
//then just access splitter.data_4[0]..[3]
|
Saves over 100bytes of code..... |
|
|
|