Page 1 of 1

Complile Issuer (memcmp, strcmp)

Posted: 23 Aug 2016 18:42
by alejandroflamerich
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

Re: Complile Issuer (memcmp, strcmp)

Posted: 24 Aug 2016 16:45
by lana.arsic
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

Re: Complile Issuer (memcmp, strcmp)

Posted: 24 Aug 2016 17:20
by alejandroflamerich
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

Re: Complile Issuer (memcmp, strcmp)

Posted: 25 Aug 2016 10:23
by filip
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.

Re: Complile Issuer (memcmp, strcmp)

Posted: 25 Aug 2016 17:18
by alejandroflamerich
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