Oooh...it's not often I can comment on Ben's replies... :-)
> You are assuming that calloc() is a supported function on PalmOS. It is
> not.
PalmOS has nothing (or little) to do with it. It's up to the development
environment.
> Here is a quick inline version that should work similar to the ANSI C
> function calloc(), and will also show you how memory is allocated on
PalmOS.
I would like to suggest that either "num" or "size" be converted to a 32-bit
value before using it in the multiplication. Otherwise, you could suffer
overflow problems. Although, if you were being strictly correct, I think
that "calloc" should be defined is it is properly declared: with size_t's.
-- Keith Rollin
-- Palm OS Emulator engineer
"Ben Combee" <[EMAIL PROTECTED]> wrote in message
news:40565@palm-dev-forum...
>
> "Carl Smith" <[EMAIL PROTECTED]> wrote in message
news:40564@palm-dev-forum...
> >
> > I have an app with numerous calls to calloc. I've included the file
> #include
> > <stdlib.h> which directs to the cstdlib file which in turn holds the
> > prototype for calloc. Now if I don't include the
> > #include <stdlib.h> I get compile errors as "Function has no prototype"
> yet
> > when I do include the stdlib.h file I get a link error of, "'calloc'
> > referenced from 'myfunction' is undefined.
> >
> > Does any body have any suggestions as to what the problem might be?
Could
> my
> > project be hitting the 64k barrier? Plus how does one tell when they are
> at
> > or above the 64k when the project will not compile?
>
> You are assuming that calloc() is a supported function on PalmOS. It is
> not.
>
> Here is a quick inline version that should work similar to the ANSI C
> function calloc(), and will also show you how memory is allocated on
PalmOS.
>
> inline void *calloc(UInt16 num, UInt16 size)
> {
> void *memory = MemPtrNew(num * size);
> if (memory)
> {
> MemSet(memory, num * size, 0);
> }
> return memory;
> }
>
> and this should match with
>
> inline void free(void *memory)
> {
> if (memory)
> {
> MemPtrFree(memory);
> }
> }
>
> since your code does deallocate memory, I'd assume.
>
> --
> Ben Combee
> Veriprise Wireless <http://www.veriprise.com>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/