The compiler does not know about StrPrintF format strings. So it does not
know that you want the literal 'R' used as a char. The compiler just pushes
the arguments as is on to the stack. The StrPrintF function then pulls
arguments off the stack base upon the format string. Since the literal is
taking up more than 1 byte on the stack, the second string pointer being
used by StrPrintF is corrupt.
The direct assignment (char c = 'R') works because the compiler 'knows' what
you are using the literal for and performs an implicit cast. The char sized
variable works in the StrPrintF call because it is actually char sized.
You can just cast the literal in the StrPrintF call instead of using an
intermediate variable: StrPrintF(display_string, "%s:%c:%s", "str1",
(char)'R', "str");
-jjf
-----Original Message-----
From: Thomas Ward [mailto:[EMAIL PROTECTED]]
Sent: Sunday, May 28, 2000 10:40 AM
To: Palm Developer Forum
Subject: StrPrintF Bug?
I have the following variable in my code:
char display_string[41];
When I try to execute the following statement:
StrPrintF(display_string, "%s:%c:%s", "str1", 'R', "str");
I get an error: "my application (version) has just written directly to
memory manager data structures."
The problem seems to have something to do with the 'R' character I am trying
to substitute, because:
StrPrintF(display_string, "%s:%s:%s", "str1", "R", "str2");
works correctly. Interestingly, if I do this:
char c = 'R';
StrPrintF(display_string, "%s:%c:%s", "str1", c, "str2");
it works fine.
This is all using the 3.5 color (non-debug) ROM. I use GCC, and compile with
the -O2 option, if it matters. According to the doc. for
StrPrintF/StrVPrintF, the %c format should be handled correctly. Anybody
know what's going on? Thanks.
Tom
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/