Thanx guys! It really helps... a lot!!!
Best Regards, Brian
Keith Rollin wrote:
At 9:09 AM -0500 10/4/03, David Cook wrote:
On Sat, Oct 04, 2003 at 05:15:23PM +0800, Brian wrote:
Has anyone encountered a problem when copying a data of type unsigned characters to Char*?
unsigned char* thisone= ""; unsigned long i = 0;
Char* putHere = 0; putHere = (Char*)(thisone + i );
I have noted that typecasting is somewhat different under the palm,
Typecasting on the palm is generally no different than in any other environment. Of course, on any platform, you'll have some idiosyncrasies, but I can't think of anything noteworthy on the Palm. (This is all avoiding the distinction, of course, that typecasting is a compiler issue, not a device issue, and so saying "typecasting ... under the palm" doesn't really make any sense.)
and
doing some unforgiving things like in a print, using "%d" but feeding it a
long, can cause a crash (which would never happen in gcc for Solaris, etc).
This is a completely different issue. I'm not sure why you're bringing it up. You're crashing (or, at least, getting incorrect results) because you're feeding printf the wrong type for the %d specifier. It has nothing to do with typecasting. You'd fail on Solaris, too, if you feed, say, a long long or a double to the %d specifier.
I personally use unsigned and signed chars and don't have the specific problem
you mention,
I don't see that the OP mentioned any specific problem. He's asking of people have problems, but he doesn't mention what problem he is encountering himself.
but I can see that it might type-cast confuse the compiler in your mixing of the long, etc.
No, there's nothing wrong (that I can see, given the provided information) with what the OP is doing.
I mean, if you look at your line you have three typecasts in it...
I'm not sure what you're looking at -- there's only one typecast that I can see (the "(Char*)").
and one
of those is not implied (e.g., your parenthesis have an unsigned char and
long math).
I'm not sure what you're getting to, here. The stuff in the parenthesis is the addition of a pointer type ("unsigned char*") and a long type. This is perfectly fine.
So, for example, one of the following should work:
1) putHere = (Char *)thisone; putHere += (unsigned char *)i;
This one should never work. It's not legal to add two pointer types to each other.
2) putHere = (Char *)(thisone + (unsigned char *)i);
Same here.
-- Keith
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
