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 support@ccsinfo.com

warning message

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
raman00084@gmail.com



Joined: 28 Jul 2014
Posts: 38

View user's profile Send private message

warning message
PostPosted: Tue Jul 04, 2023 3:07 am     Reply with quote

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: 9120
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 04, 2023 5:12 am     Reply with quote

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: 19236

View user's profile Send private message

PostPosted: Tue Jul 04, 2023 11:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 05, 2023 4:04 am     Reply with quote

i am passing unsigned int8 to char.
the problem solved
Ttelmah



Joined: 11 Mar 2010
Posts: 19236

View user's profile Send private message

PostPosted: Wed Jul 05, 2023 6:15 am     Reply with quote

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.....
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