I'm trying to use two functions from string library.
strcmp() doesn't accept pointers to constant strings as an parameter
strcpy() accepts pointers to constant strings
Does anybody know the reason, both functions behave in a different ways?
There is information in CCS manual that CCS doesn't allow pointers to a constant to be used but why exception for strcpy()?
I'm using PCB V4.042 compiler.
Ttelmah Guest
Posted: Tue Jul 24, 2007 8:08 am
So you can use the strcpy function to copy the constant to RAM, and then use the other functions on it there.
The function is 'under the skin', overloaded, with two different functions present. The first is the normal 'string' pointer version, while the other treats the source as a function returning a byte from an indexed location. This code makes the function bulkier (which is why it is only in this one function), but then allows it to be used to make the other functions work.
Best Wishes
typek
Joined: 24 Jul 2007 Posts: 1
Posted: Tue Jul 24, 2007 3:27 pm
I've made a mistake in the subject of the post. The name of the second function is of course strcpy() and not strcmpy() which was obviously noticed by you.
Your explanation sounds logical. The idea of having just one function which can operate on constants is a bit irritating in use though;) I'd prefer not to be forced to waste RAM just on the temporary buffer for keeping copies of the strings. At least I know now that the way it works is intentional.
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