I've been watching the responses on this thread with some amazement, because so far, no one has noticed the essential problem: it's a compiler bug all right, for not rejecting the code out of hand!

It's the first statement in the function that's wrong. Some choices for statements that would be *right* are:

static const char threeChars[] = "123";

static const char threeChars[] = {'1', '2', '3'};

static const char *threeChars[] = {"123"};

The first and third are misnomers: the first generates a four-member array of characters ('1', '2', '3', and '\0'), and the third generates a one-member array of pointers to character arrays (strings). The second generates what the variable name promises.

I have trouble guessing what the original code generates. Evidently something pretty weird.

Greg Lutz
NearSpace, Inc.


At 08:53 AM 12/8/2003, Gregg Woodcock wrote:
I am trying to be a GoodCoder (TM) and did a global replace to conform to
the Palm standard data type naming convention (e.g. "int" -> "Int16", etc.).
I use cygwin/GCC and have encountered a strange bug after this conversion.
Please don't ask why I am doing it this way because really I'm not; this is
just a stripped-down, bare-bones hunk of code which demonstrates the
problem.  On POSE, I get "<App> just read from memory location <loc> which
is in an unallocated chunk of memory."  On a real device, it just chugs and
chugs forever in some kind of infinite loop (addressing through the
'threeChars' string/array).

NOTE: the precipitating change is the "char" changing to "Char".

void NoBugTest(void) // This code works fine:
{
   static const char threeChars[] = {"123"};
   UInt8 i = 0;
   UInt16 j=0;

   FrmCustomAlert(alertWith3Vars, "<", ((threeChars[i] != NULL) ? "not NULL"
: "NULL"));
   FrmCustomAlert(alertWith3Vars, "<", ((threeChars[j] != NULL) ? "not NULL"
: "NULL"));}

void BugTest(void) // This code has array bound (infinite loop) errors:
{
   static const Char threeChars[] = {"123"};
   UInt8 i = 0;
   UInt16 j=0;

   FrmCustomAlert(alertWith3Vars, "<", ((threeChars[0] != NULL) ? "not NULL"
: "NULL")); // <- OK!
   FrmCustomAlert(alertWith3Vars, "<", ((threeChars[i] != NULL) ? "not NULL"
: "NULL")); // <- BAD #1!
   FrmCustomAlert(alertWith3Vars, "<", ((threeChars[j] != NULL) ? "not NULL"
: "NULL")); // <-BAD #2!
}




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




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

Reply via email to