Complile Issuer (memcmp, strcmp)

Here you can find latest news on mikroElektronika products.
Post Reply
Author
Message
alejandroflamerich
Posts: 68
Joined: 17 Jan 2008 19:32
Location: Venezuela
Contact:

Complile Issuer (memcmp, strcmp)

#1 Post by alejandroflamerich » 23 Aug 2016 18:42

This is a simple issue that I would want to know about it.

int memcmp(void *s1, void *s2, int n);
void suppous void right? I can use any type so..

I suppose that i can compare char* with const char * pointer and to the contrary the compiler return is... Ilegal pointer.
Which is the right function to compare a string RAM memory with string ROM memory?

What about int strncmp(char *s1, char *s2, char len);
why I cant cast in this function ej:
char x[]="abdc";
const char y[]="abcdFGHI";

int strncmp(x, (char *)y, 4); //It in mikroC doesnot work.


Any idea? Regards

Alejandro

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Complile Issuer (memcmp, strcmp)

#2 Post by lana.arsic » 24 Aug 2016 16:45

Hi Alejandro,

I have tested your code and both functions memcmp and strncmp compile without error
and give appropriate results if you are comparing char with const char.

Can you tell me which MCU, compiler and version of the compiler do you use?

Best regards,
Lana

alejandroflamerich
Posts: 68
Joined: 17 Jan 2008 19:32
Location: Venezuela
Contact:

Re: Complile Issuer (memcmp, strcmp)

#3 Post by alejandroflamerich » 24 Aug 2016 17:20

Hi Lana.

Thank you for you soon answer

MicroC 6.6.3 PIC18F87J60

this is my code

char * pcStringCommand = "help arg1 arg2 arg3";
const char * const pcCommand ="help";

strcmp(pcStringCommand, pcCommand); //it does not compile
strncmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile
memcmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile neither

Could you copy/paste your code here. I appreciate it.

Regards

Alejandro

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Complile Issuer (memcmp, strcmp)

#4 Post by filip » 25 Aug 2016 10:23

Hi,

I see the issue now, Lana probably tried constant pointer instead of of pointer to constant.
Due to the architecture specifics, the pointers to RAM and ROM are not compatible, so the compiler issues an error due to this.

To solve this, you can do one of these things :
1. Copy string from ROM to RAM,
2. Use comparing function that handles ROM strings.

Regards,
Filip.

alejandroflamerich
Posts: 68
Joined: 17 Jan 2008 19:32
Location: Venezuela
Contact:

Re: Complile Issuer (memcmp, strcmp)

#5 Post by alejandroflamerich » 25 Aug 2016 17:18

Hi Filip.

Thanks for your reply.

Yeap. That's what Im doing. So I worder if I could do a casting like (char*) or something. But I see that not.

Regards for your support.

Alejandro

Post Reply

Return to “Product Announcements”