Hi, I am trying to get strncpy working. At the moment I know that it has something to do with the newlib. I am using coocox with https://launchpad.net/gcc-arm-embedded/ How do I include the newlib into my toolchain? Or am I wrong with newlib an the problem lies somewhere else? I included the syscalls from the repository: "The component implement the minimal functionality required to allow libc to link." I also included libc in the "linked libraries section". But it seems as if behind strncpy is only a declaration: "char *_EXFUN(strncpy,(char *, const char *, size_t));" I do not have any compile errors, but the strncpy is not working.
OK, I was searching a little bit for the reason. I am actually asm-debugging the code. It seem that the strncpy is linked correct, the program jumps to a routine called strncpy. Also the operations like copy first address of sourcestring to r2, copy first address of destination address to.. and so on. But the line is working: strb.w r5, [r4], #1 At this line the value 0x36 ("6") should be copied to the new address (0x08003984), right? But nothing is happening, the old value "y" is still there! The disassembly is at the picture. Whats wrong?
So, I found the solution: If I declare
1 | char to[6]; |
then the var will be somewhere in RAM and the value can be changed. I declare
1 | char to = "yyyyyy"; |
then the var will be somewhere in Flash and the value can not be changed. Whats the reason for this and how can I declare on which place in memory I want my vars?
Marcel F. wrote: > Whats the reason for this Because the standard demands that a string literal will not be changed. And the compiler saves precious RAM depending on that stipulation. A good reason to learn C, wouldn't you think? > and how can I declare on which place in memory I want my vars? Read your compiler's documentation. There is probably some attribute or pragma to put it in whatever type of memory you want.
thanks, I already got the solution. The solution is: If I declare
1 | char *to = "yyyyyy"; |
, then it is a constant value, but if I declare like
1 | char to[7] = "yyyyyy"; |
then it is not a constant. This information helped me in another forum. Your "help" was no help. If you are telling everyone with a question that he should learn more or read a book, what kind of help is this? Better save your time :)
You learned from my answer that the behaviour is correct and to be expected. You didn't know that and were confused. So this point alone was real help. Additionally I directed you to the best place to find the answer to your explicit question. Since you don't seem to be intellectually able to understand answers, and furthermore you have some really nasty sense of entitlement, please don't post here again. You're simply not welcome.
char to="asdf"; is just wrong, since you're trying to assing an array field to one single element. char to[]="asdf"; or char to[5]="asdf"; is correct. first one as mentioned is only a single element. The compiler should recognize that this is not correct, maybe add "-Wall" to your compile command to show up a warning message.
Yes, Tobias, in my third post i forgot the "*" :) sorry for that
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.