In a message dated 10/23/00 12:18:17 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:

<< > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 > I'm a little suspicious of your StrCopy() function call.
 > I would imagine that you shouldn't be using StrCopy() when
 > it is pointing to the constant string "12:34.5".
 
 Correct.  String literals live in read-only memory on Palm.
 
 > I tried it on my compiler (BorlandC++/Win98), and it 
 > worked fine, but I don't know why.
 
 It compiles only due to an unfortunate quirk in the C/C++ type system.
 String literals are considered (char *) instead of (const char *).  I don't
 know why, except that C++ inherits this feature from C for compatibility.
 (See Stroustrup 3rd Ed., section 5.2.2.)
 
 This permits pathological code like this.  Don't try this at home:
 
     *"a" = 'b'; // compiles ok, crashes at runtime on Palm
 
 > I would have figured that it would have given me an exception
 > for trying to write into memory that only has read access.
 
 The actual runtime behavior is platform dependent.  Your Borland Win32
 compiler may put string literals in a writable data segment.  I recall using
 this trick on Windows years ago.
 
 -slj-
  >>

Cool! Thanks for the explaination.

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to