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

New compiler Warning

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

New compiler Warning
PostPosted: Thu Apr 07, 2016 9:43 am     Reply with quote

I was using compiler 5.025 ok now I updated to 5.056 and new warnings appears.

Pointer types do not match


Code:
long long FlagsRules1;
long long FlagsRules2;
long long FlagsRules3;
char FlagsRules4;

#define EE_R99   3999
#define FlagsRules1_EE EE_R99 + 1

void WriteBufferEE(long StartAddress, char *DataBuffer, char ByteCount)
{
   //....code here
   
}   

void UpdateRuleX(char Num, short Enable)
{
        if(Num<32)
        {
            if(enable)
            {
                bit_set(FlagsRules1,Num);
            }
            else
            {
                bit_clear(FlagsRules1,Num);
            }
         WriteBufferEE(FlagsRules1_EE,&FlagsRules1,4);//<--- Warning HERE
      }
      else if(Num<64)
      {
         //More code here..
      }   
}   


Can somebody tell me what I'm doing wrong?
_________________
Electric Blue
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 10:14 am     Reply with quote

Well. look at that line. You told the compiler that the function accepts
the address of a char pointer. Then you give it a parameter (the middle
one), that is the address of a 'long long'. How does the compiler know
that your 'long long' is a char buffer ? It doesn't. If you want to do that,
you have to tell the compiler what you're doing. This is done with a cast:
Quote:
WriteBufferEE(FlagsRules1_EE, &(char *)FlagsRules1, 4);
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 11:09 am     Reply with quote

and, checking for this type of problem, has been successively tightened on the last few compiler versions, so 'more warnings' will occur on older code.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 1:07 pm     Reply with quote

Ok, now I changed the code to

Code:
WriteBufferEE(FlagsRules1_EE,&(char)(FlagsRules1),4);


But generates the same amount of instructions
Do I still wrong?

Does it worth to explicitly make a cast? Because seem like the compiler was already casting to char.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 2:13 pm     Reply with quote

First, it is a warning. These tell you something _may_ be wrong, not that it is.
Then, why should the number of instructions change?.

The key point about 'types' with pointers, is that these tell the compiler how _big_ something is. If you have a char pointer, and increment it, it moves forwards by one 'char' sized lump. If you increment a pointer to a 'long', it instead moves forward by a 'long' sized lump.

Now, your buffer 'write' code, may well internally always treat the pointers as 'char' sized, but if you hand to this a pointer to something of a different size, then you should be made aware that the sizes used in the function, _may not_ be the sizes you expect. The cast says to the compiler "I understand that I am actually going to deal with this in bytes, so don't warn me".

There are many occasions where warnings can be ignored. However, In a few months time, you might be dealing with a function, where you actually _want_ to handle the variable in larger pieces, and then the warning would say 'look out' the size being used in this function, is _not_ the one you expect....
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 3:07 pm     Reply with quote

Ok, so, Whats about this?

Code:

#define APN1 Vector5 + 53//

char APN_Offset,APN_Len;
WriteBufferEE(APN1,APN_Offset,APN_Len);


Both, APN_Offset and APN_Len are char type, so Why is warning me?
_________________
Electric Blue
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 3:24 pm     Reply with quote

Because you are giving it a char when it expects a pointer to a char
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 5:04 pm     Reply with quote

And in that case as it would lead to a horrible bug ( passing in a char when a pointer is expected ). You would be accessing memory that is not intended to be accessed.
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