Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem in string.h lib in codevision

Status
Not open for further replies.

tariq70

New Member
hi
I'm using codevision AVR. in string.h lib when one of the arrays is const an error occurs.

for example i want to put a array of string from one array to another like this :

unsigned char A[11];
const unsigned char B[11]={"HELLOWORLD"};

when i use strncpy like this:

strncpy(A,B,10);

i have this error

Error:, #included from: main.c: function argument #2 of type 'flash unsigned char [11]' is incompatible with required parameter of type 'unsigned char *'

and this is the same for all of string.h lib functions.

in ARM and keil compiler i didn't had this problem but in codevision error occurs.

i know i can use for loop but is there any way to avoid this error?
 
Drop the unsigned from parameter A.. In compiler options you should be able to suppress the error to a warning..

Its saying "You said that Argument A was a normal char!! Whah boo hoo"..

Some compilers are too strict or just do this.

strncpy((char)A,B,10) ;
 
i droped the unsigned and still have the same error it says that flash char is incompatible with char so the problem is the const type if i put both array unsigned or signed it work but if one of them become const error occurs I'm looking for a way to avoid this
 
const types may be stored in program memory rather than data memory. If the CPU architecture in question cannot use the same instruction for both areas, const types have to be handled using special instructions.
 
Last edited:
Try using memcpy() instead, it looks to use the same arguments & the second parameter is a const *
 
const types may be stored in program memory rather than data memory. If the CPU architecture in question cannot use the same instruction for both areas, const types have to be handled using special instructions.
Normally in this case, they will have thier own "special" routines.. I would also use a workaround.. Sprintf() is normally in the stdio.h and can handle this.

sprintf( A , "HELLO WORLD!");

Will do the same thing.. Most embedded tools have this tool.
 
Does removing the 'const' from B make the error 'go away'?

If not, what about using: strncpy( A, B, 11 );?
 
I normally (in C) define two buffers, one to hold the final string and one to build parts in.
I.E.
char buff[128];
char buf[10];
strcpy(buf,"Hello World");
strcat(buff.buf);
itoa(var,buf,10);
strcat(buff,buf);

Mike.
BTW, did codevision really add an n to strcpy to become strncpy?
 
strncpy is standard C.
Copy a set number of characters (3rd argument), rather than copying to a null.
 
Drop the unsigned from parameter A.. In compiler options you should be able to suppress the error to a warning..

Its saying "You said that Argument A was a normal char!! Whah boo hoo"..

Some compilers are too strict or just do this.

strncpy((char)A,B,10) ;
Normally in this case, they will have thier own "special" routines.. I would also use a workaround.. Sprintf() is normally in the stdio.h and can handle this.

sprintf( A , "HELLO WORLD!");

Will do the same thing.. Most embedded tools have this tool.
Normally in this case, they will have thier own "special" routines.. I would also use a workaround.. Sprintf() is normally in the stdio.h and can handle this.

sprintf( A , "HELLO WORLD!");

Will do the same thing.. Most embedded tools have this tool.
my problem is not only strcpy I'm using strncmp and strstr. i can use sprintf instead of strcpy but what about others?
 
Was here a question, yes. Big question mark. Still don"t understand why.
Mike.
 
Try using memcpy() instead, it looks to use the same arguments & the second parameter is a const *
you mean this:
char A[10];
const char *B[11]={"helloworld"};

memcpy(A,B,10);
it doesnt have an error but seems not working after building project char A wasn't helloworld

i think best option is i make my own function with for loop
 
Does removing the 'const' from B make the error 'go away'?

If not, what about using: strncpy( A, B, 11 );?
yes removing the const make the error go away but i want to do it with const.
const char stores in flash but char stores in ram i want to optimize my ram usage so i have to use const.
 
yes removing the const make the error go away but i want to do it with const.
const char stores in flash but char stores in ram i want to optimize my ram usage so i have to use const.

Then use:
1627666306323.png
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top