[EMAIL PROTECTED] wrote in message <[EMAIL PROTECTED]>...
>
>[EMAIL PROTECTED] wrote:
>> > static void foo()
>> > {
>> >    Char badboy[100];
>> >    StrCopy(badboy, "I cause program counter modifications\0");
>> > }
>>
>> Looks fine to me, assuming that there are 100 bytes available on the
stack at
>> the time you call foo().  That "\0" at the end of your string looks
silly, but
>> it shouldn't cause any problems.
>
>Hmmm... my experience is that if I didn't put a '\0' at the end, StrCopy
>would cause a few "memory allocation" error messages to pop up. My
>initial guess was that during runtime, StrCopy(a, b) couldn't find the
>proper end of b and kept reading past my string until it finds a '\0'
>somewhere down the (memory) lane. Is that how StrCopy() works?

That is indeed how StrCopy works ... but the compiler is responsible
for putting a '\0' at the end of all string literals.  That is to say, when
the
code says "hello", the compiler puts [ 'h', 'e', 'l', 'l', 'o', '\0' ]
somewhere
in memory for you.  "hello\0" would result in [ 'h', 'e', 'l', 'l', 'o',
'\0', '\0' ].
Completely redundant string termination.  Not harmful, but redundant
and a little odd-looking.

>I've sent
>in the agreement for the release of the PalmOS sourcecode but do not
>have a reply yet. (It has been about 5 weeks now, not that I'm
>complaining.)

Go ahead and complain.  That sometimes helps the process <g>

>
>> I'll bet that creating a new project, slapping in the above function, and
>> calling it won't turn up any problems.  I'm guessing the source of your
crash is
>> elsewhere.
>Well, I've tried using StrCopy() (like above) in the Memopad app
>tutorial, and it bombed POSE. Is it some CW6 setting that I've neglected
>to set/disable/modify ?
>
>> > Can anyone tell me what I did wrong? Do I have to do badboy =
>> > MemPtrNew(100); everytime I want to use StrCopy(), or StrPrintF() and
>> > such?
>>
>> No, you don't have to call MemPtrNew.  Doing a StrCopy to a stack-based
array of
>> chars should be OK, as long as the source is smaller than the
destination.
>OK, another slap on my hand for not keeping awake during CS501
>(Compilers and Operating Systems) lectures, I beg to ask this : "when is
>an array not stack-based?"

When it is heap-based.  (i.e. allocated w/ MemPtrNew or MemHandleNew).
Actually there is another one in the Palm world: Database-based.  If you
get a record from your db & lock it down, the pointer is straight into your
database.  (I think ...)

--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!






-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to